~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/widget/src/beos/nsLookAndFeel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 * Sergei Dolgov <sergei_d@fi.tartu.ee>
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the NPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the NPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#include "nsLookAndFeel.h"
 
40
#include "nsFont.h"
 
41
#include "nsSize.h"
 
42
 
 
43
#include <InterfaceDefs.h>
 
44
#include <Menu.h>
 
45
 
 
46
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
 
47
{
 
48
}
 
49
 
 
50
nsLookAndFeel::~nsLookAndFeel()
 
51
{
 
52
}
 
53
 
 
54
nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor)
 
55
{
 
56
  nsresult res = NS_OK;
 
57
  rgb_color color;
 
58
  /*
 
59
   * There used to be an entirely separate list of these colors in
 
60
   * nsDeviceContextBeOS::GetSystemAttribute.  The colors given there
 
61
   * were a bit different from these.  If these are inaccurate, it might
 
62
   * be worth looking at cvs history for the ones there to see if they
 
63
   * were better.
 
64
   */
 
65
 
 
66
  switch (aID) {
 
67
    case eColor_WindowBackground:
 
68
      aColor = NS_RGB(0xff, 0xff, 0xff); 
 
69
      break;
 
70
    case eColor_WindowForeground:
 
71
      aColor = NS_RGB(0x00, 0x00, 0x00);        
 
72
      break;
 
73
    case eColor_WidgetBackground:
 
74
      aColor = NS_RGB(0xdd, 0xdd, 0xdd);
 
75
      break;
 
76
    case eColor_WidgetForeground:
 
77
      aColor = NS_RGB(0x00, 0x00, 0x00);        
 
78
      break;
 
79
    case eColor_WidgetSelectBackground:
 
80
      {
 
81
        color = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR);
 
82
        aColor = NS_RGB(color.red, color.green, color.blue);
 
83
      }
 
84
      break;
 
85
    case eColor_WidgetSelectForeground:
 
86
      aColor = NS_RGB(0x00, 0x00, 0x80);
 
87
      break;
 
88
    case eColor_Widget3DHighlight:
 
89
      aColor = NS_RGB(0xa0, 0xa0, 0xa0);
 
90
      break;
 
91
    case eColor_Widget3DShadow:
 
92
      aColor = NS_RGB(0x40, 0x40, 0x40);
 
93
      break;
 
94
    case eColor_TextBackground:
 
95
      aColor = NS_RGB(0xff, 0xff, 0xff);
 
96
      break;
 
97
    case eColor_TextForeground: 
 
98
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
99
      break;
 
100
    case eColor_TextSelectBackground:
 
101
      {
 
102
        // looks good in Mozilla, though, never noticed this color in BeOS menu
 
103
        color = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR);
 
104
        aColor = NS_RGB(color.red, color.green, color.blue);
 
105
      }
 
106
      break;
 
107
    case eColor_TextSelectForeground:
 
108
      {
 
109
        color = ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR);
 
110
        aColor = NS_RGB(color.red, color.green, color.blue);
 
111
      }
 
112
      break;
 
113
        // two following colors get initialisation in XPLookAndFeel.
 
114
        //eColor_TextSelectBackgroundDisabled,
 
115
    //eColor_TextSelectBackgroundAttention,
 
116
    
 
117
    //  CSS 2 Colors
 
118
    case eColor_activeborder:
 
119
      aColor = NS_RGB(0x88, 0x88, 0x88);
 
120
      break;
 
121
    // active titletab
 
122
    case eColor_activecaption:
 
123
      {
 
124
        color = ui_color(B_WINDOW_TAB_COLOR);
 
125
        aColor = NS_RGB(color.red, color.green, color.blue);
 
126
      }    
 
127
      break;
 
128
    //MDI color
 
129
    case eColor_appworkspace:
 
130
      aColor = NS_RGB(0xd8, 0xd8, 0xd8);
 
131
      break;
 
132
    //incidentally, this is supposed to be the colour of the desktop, though how anyone
 
133
    //is supposed to guess that from the name?
 
134
    case eColor_background:
 
135
      {
 
136
        color = ui_color(B_DESKTOP_COLOR);
 
137
        aColor = NS_RGB(color.red, color.green, color.blue);
 
138
      }
 
139
      break;
 
140
    case eColor_buttonface:
 
141
      aColor = NS_RGB(0xdd, 0xdd, 0xdd);
 
142
      break;
 
143
    //should be lighter of 2 possible highlight colours available
 
144
    case eColor_buttonhighlight:
 
145
      aColor = NS_RGB(0xff, 0xff, 0xff);
 
146
      break;
 
147
    //darker of 2 possible shadow colours available
 
148
    case eColor_buttonshadow:
 
149
      aColor = NS_RGB(0x77, 0x77, 0x77);
 
150
      break;
 
151
    case eColor_buttontext:
 
152
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
153
      break;
 
154
    case eColor_captiontext:
 
155
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
156
      break;
 
157
    case eColor_graytext:
 
158
      aColor = NS_RGB(0x77, 0x77, 0x77);
 
159
      break;
 
160
    case eColor_highlight:
 
161
      {
 
162
        // B_MENU_SELECTION_BACKGROUND_COLOR  is used for text selection
 
163
        // this blue colors seems more suitable
 
164
        color = ui_color(B_KEYBOARD_NAVIGATION_COLOR);
 
165
        aColor = NS_RGB(color.red, color.green, color.blue);
 
166
      }
 
167
      break;
 
168
    case eColor_highlighttext:
 
169
      {
 
170
        color = ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR);
 
171
        aColor = NS_RGB(color.red, color.green, color.blue);
 
172
      }
 
173
      break;
 
174
    case eColor_inactiveborder:
 
175
      aColor = NS_RGB(0x55, 0x55, 0x55);
 
176
      break;
 
177
    case eColor_inactivecaption:
 
178
      aColor = NS_RGB(0xdd, 0xdd, 0xdd);
 
179
      break;
 
180
    case eColor_inactivecaptiontext:
 
181
      aColor = NS_RGB(0x77, 0x77, 0x77);
 
182
      break;
 
183
    case eColor_infobackground:
 
184
      // tooltips
 
185
      aColor = NS_RGB(0xff, 0xff, 0xd0);
 
186
      break;
 
187
    case eColor_infotext:
 
188
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
189
      break;
 
190
    case eColor_menu:
 
191
      {
 
192
        color = ui_color(B_MENU_BACKGROUND_COLOR);
 
193
        aColor = NS_RGB(color.red, color.green, color.blue);
 
194
      }
 
195
      break;
 
196
    case eColor_menutext:
 
197
      {
 
198
        color = ui_color(B_MENU_ITEM_TEXT_COLOR);
 
199
        aColor = NS_RGB(color.red, color.green, color.blue);
 
200
      }
 
201
      break;
 
202
    case eColor_scrollbar:
 
203
      aColor = NS_RGB(0xaa, 0xaa, 0xaa);
 
204
      break;
 
205
    case eColor_threeddarkshadow:
 
206
      aColor = NS_RGB(0x77, 0x77, 0x77);
 
207
      break;
 
208
    case eColor_threedface:
 
209
      aColor = NS_RGB(0xdd, 0xdd, 0xdd);
 
210
      break;
 
211
    case eColor_threedhighlight:
 
212
      aColor = NS_RGB(0xff, 0xff, 0xff);
 
213
      break;
 
214
    case eColor_threedlightshadow:
 
215
      aColor = NS_RGB(0xdd, 0xdd, 0xdd);
 
216
      break;
 
217
    case eColor_threedshadow:
 
218
      aColor = NS_RGB(0x99, 0x99, 0x99);
 
219
      break;
 
220
    case eColor_window:
 
221
      aColor = NS_RGB(0xff, 0xff, 0xff);
 
222
      break;
 
223
    case eColor_windowframe:
 
224
      aColor = NS_RGB(0xcc, 0xcc, 0xcc);
 
225
      break;
 
226
    case eColor_windowtext:
 
227
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
228
      break;
 
229
    // CSS3 candidates
 
230
    case eColor__moz_field: 
 
231
      // normal widget background
 
232
      aColor = NS_RGB(0xff, 0xff, 0xff);
 
233
      break;  
 
234
    case eColor__moz_fieldtext:
 
235
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
236
      break;  
 
237
    case eColor__moz_dialog:
 
238
      //all bars  including MenuBar
 
239
      aColor = NS_RGB(0xdd, 0xdd, 0xdd);
 
240
      break;  
 
241
    case eColor__moz_dialogtext:
 
242
      aColor = NS_RGB(0x00, 0x00, 0x00);
 
243
      break;  
 
244
    case eColor__moz_dragtargetzone:
 
245
      aColor = NS_RGB(0x63, 0x63, 0xCE);
 
246
      break;
 
247
    case eColor__moz_buttondefault:
 
248
      aColor = NS_RGB(0x77, 0x77, 0x77);
 
249
      break;
 
250
    case eColor_LAST_COLOR:
 
251
    default:
 
252
      aColor = NS_RGB(0xff, 0xff, 0xff);
 
253
      res    = NS_ERROR_FAILURE;
 
254
      break;
 
255
  }
 
256
 
 
257
  return res;
 
258
}
 
259
  
 
260
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
 
261
{
 
262
  nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
 
263
  if (NS_SUCCEEDED(res))
 
264
    return res;
 
265
  res = NS_OK;
 
266
 
 
267
  /*
 
268
   * There used to be an entirely separate list of these metrics in
 
269
   * nsDeviceContextBeOS::GetSystemAttribute.  The metrics given there
 
270
   * were a bit different from these.  If these are inaccurate, it might
 
271
   * be worth looking at cvs history for the ones there to see if they
 
272
   * were better.
 
273
   */
 
274
 
 
275
  switch (aID) 
 
276
  {
 
277
    case eMetric_WindowTitleHeight:
 
278
      // 2*horizontal scrollbar height
 
279
      aMetric = 28;
 
280
      break;
 
281
    case eMetric_WindowBorderWidth:
 
282
      aMetric = 2;
 
283
      break;
 
284
    case eMetric_WindowBorderHeight:
 
285
      aMetric = 2;
 
286
      break;
 
287
    case eMetric_Widget3DBorder:
 
288
      aMetric = 5;
 
289
      break;
 
290
    case eMetric_TextFieldBorder:
 
291
      aMetric = 3;
 
292
      break;
 
293
    case eMetric_TextFieldHeight:
 
294
      aMetric = 24;
 
295
      break;
 
296
    case eMetric_TextVerticalInsidePadding:
 
297
      aMetric = 0;
 
298
      break;    
 
299
    case eMetric_TextShouldUseVerticalInsidePadding:
 
300
      aMetric = 0;
 
301
      break;
 
302
    case eMetric_TextHorizontalInsideMinimumPadding:
 
303
      aMetric = 3;
 
304
      break;
 
305
    case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
 
306
      aMetric = 1;
 
307
      break;    
 
308
    case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
 
309
      aMetric = 10;
 
310
      break;
 
311
    case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
 
312
      aMetric = 8;
 
313
      break;
 
314
    case eMetric_CheckboxSize:
 
315
      aMetric = 12;
 
316
      break;
 
317
    case eMetric_RadioboxSize:
 
318
      aMetric = 12;
 
319
      break;
 
320
 
 
321
    case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
 
322
      aMetric = 0;
 
323
      break;
 
324
    case eMetric_ListHorizontalInsideMinimumPadding:
 
325
      aMetric = 3;
 
326
      break;
 
327
      
 
328
    case eMetric_ListShouldUseVerticalInsidePadding:
 
329
      aMetric = 0;
 
330
      break;
 
331
    case eMetric_ListVerticalInsidePadding:
 
332
      aMetric = 0;
 
333
      break;
 
334
      
 
335
    case eMetric_CaretBlinkTime:
 
336
      aMetric = 500;
 
337
      break;
 
338
    case eMetric_SingleLineCaretWidth:
 
339
      aMetric = 1;
 
340
      break;
 
341
    case eMetric_MultiLineCaretWidth:
 
342
      aMetric = 2;
 
343
      break;
 
344
    case eMetric_ShowCaretDuringSelection:
 
345
      aMetric = 1;
 
346
      break;
 
347
    case eMetric_SelectTextfieldsOnKeyFocus:
 
348
      // Do not select textfield content when focused by kbd
 
349
      // used by nsEventStateManager::sTextfieldSelectModel
 
350
      aMetric = 0;
 
351
      break;
 
352
    case eMetric_SubmenuDelay:
 
353
      aMetric = 500;
 
354
      break;
 
355
    case eMetric_MenusCanOverlapOSBar: // can popups overlap menu/task bar?
 
356
      aMetric = 0;
 
357
      break;
 
358
    case eMetric_DragFullWindow:
 
359
      aMetric = 0;
 
360
      break;
 
361
    case eMetric_ScrollArrowStyle:
 
362
      {
 
363
        aMetric = eMetric_ScrollArrowStyleBothAtEachEnd; // BeOS default
 
364
 
 
365
        scroll_bar_info info;
 
366
        if(B_OK == get_scroll_bar_info(&info) && !info.double_arrows)
 
367
        {
 
368
          aMetric = eMetric_ScrollArrowStyleSingle;
 
369
        }
 
370
      }
 
371
      break;
 
372
    case eMetric_ScrollSliderStyle:
 
373
      {
 
374
        aMetric = eMetric_ScrollThumbStyleProportional; // BeOS default
 
375
 
 
376
        scroll_bar_info info;
 
377
        if(B_OK == get_scroll_bar_info(&info) && !info.proportional)
 
378
        {
 
379
          aMetric = eMetric_ScrollThumbStyleNormal;
 
380
        }
 
381
      }
 
382
      break;
 
383
    case eMetric_TreeOpenDelay:
 
384
      aMetric = 1000;
 
385
      break;
 
386
    case eMetric_TreeCloseDelay:
 
387
      aMetric = 1000;
 
388
      break;
 
389
    case eMetric_TreeLazyScrollDelay:
 
390
      aMetric = 150;
 
391
      break;
 
392
    case eMetric_TreeScrollDelay:
 
393
      aMetric = 100;
 
394
      break;
 
395
    case eMetric_TreeScrollLinesMax:
 
396
      aMetric = 3;
 
397
      break;
 
398
    default:
 
399
        aMetric = 0;
 
400
        res = NS_ERROR_FAILURE;
 
401
    }
 
402
  return res;
 
403
}
 
404
 
 
405
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
 
406
{
 
407
  nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
 
408
  if (NS_SUCCEEDED(res))
 
409
    return res;
 
410
  res = NS_OK;
 
411
 
 
412
  switch (aID) {
 
413
    case eMetricFloat_TextFieldVerticalInsidePadding:
 
414
        aMetric = 0.25f;
 
415
        break;
 
416
    case eMetricFloat_TextFieldHorizontalInsidePadding:
 
417
        aMetric = 0.95f;
 
418
        break;
 
419
    case eMetricFloat_TextAreaVerticalInsidePadding:
 
420
        aMetric = 0.40f;
 
421
        break;
 
422
    case eMetricFloat_TextAreaHorizontalInsidePadding:
 
423
        aMetric = 0.40f;
 
424
        break;
 
425
    case eMetricFloat_ListVerticalInsidePadding:
 
426
        aMetric = 0.10f;
 
427
        break;
 
428
    case eMetricFloat_ListHorizontalInsidePadding:
 
429
        aMetric = 0.40f;
 
430
        break;
 
431
    case eMetricFloat_ButtonVerticalInsidePadding:
 
432
        aMetric = 0.25f;
 
433
        break;
 
434
    case eMetricFloat_ButtonHorizontalInsidePadding:
 
435
        aMetric = 0.25f;
 
436
        break;
 
437
    default:
 
438
        aMetric = -1.0;
 
439
        res = NS_ERROR_FAILURE;
 
440
    }
 
441
  return res;
 
442
}