[4dc017]: widget / xpwidgets / nsNativeTheme.cpp Maximize Restore History

Download this file

nsNativeTheme.cpp    705 lines (599 with data), 20.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsNativeTheme.h"
#include "nsIWidget.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsEventStateManager.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLProgressElement.h"
#include "nsIDOMXULMenuListElement.h"
#include "nsThemeConstants.h"
#include "nsIComponentManager.h"
#include "nsPIDOMWindow.h"
#include "nsProgressFrame.h"
#include "nsMeterFrame.h"
#include "nsMenuFrame.h"
#include "nsRangeFrame.h"
#include "nsCSSRendering.h"
#include "mozilla/dom/Element.h"
#include <algorithm>
nsNativeTheme::nsNativeTheme()
: mAnimatedContentTimeout(UINT32_MAX)
{
}
NS_IMPL_ISUPPORTS1(nsNativeTheme, nsITimerCallback)
nsIPresShell *
nsNativeTheme::GetPresShell(nsIFrame* aFrame)
{
if (!aFrame)
return nullptr;
// this is a workaround for the egcs 1.1.2 not inlining
// aFrame->PresContext(), which causes an undefined symbol
nsPresContext *context = aFrame->StyleContext()->RuleNode()->PresContext();
return context ? context->GetPresShell() : nullptr;
}
nsEventStates
nsNativeTheme::GetContentState(nsIFrame* aFrame, uint8_t aWidgetType)
{
if (!aFrame)
return nsEventStates();
bool isXULCheckboxRadio =
(aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_RADIO) &&
aFrame->GetContent()->IsXUL();
if (isXULCheckboxRadio)
aFrame = aFrame->GetParent();
if (!aFrame->GetContent())
return nsEventStates();
nsIPresShell *shell = GetPresShell(aFrame);
if (!shell)
return nsEventStates();
nsIContent* frameContent = aFrame->GetContent();
nsEventStates flags;
if (frameContent->IsElement()) {
flags = frameContent->AsElement()->State();
}
if (isXULCheckboxRadio && aWidgetType == NS_THEME_RADIO) {
if (IsFocused(aFrame))
flags |= NS_EVENT_STATE_FOCUS;
}
// On Windows and Mac, only draw focus rings if they should be shown. This
// means that focus rings are only shown once the keyboard has been used to
// focus something in the window.
#if defined(XP_MACOSX)
// Mac always draws focus rings for textboxes and lists.
if (aWidgetType == NS_THEME_TEXTFIELD ||
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
aWidgetType == NS_THEME_SEARCHFIELD ||
aWidgetType == NS_THEME_LISTBOX) {
return flags;
}
#endif
#if defined(XP_WIN)
// On Windows, focused buttons are always drawn as such by the native theme.
if (aWidgetType == NS_THEME_BUTTON)
return flags;
#endif
#if defined(XP_MACOSX) || defined(XP_WIN)
nsIDocument* doc = aFrame->GetContent()->OwnerDoc();
nsPIDOMWindow* window = doc->GetWindow();
if (window && !window->ShouldShowFocusRing())
flags &= ~NS_EVENT_STATE_FOCUS;
#endif
return flags;
}
/* static */
bool
nsNativeTheme::CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom)
{
if (!aFrame)
return false;
nsIContent* content = aFrame->GetContent();
if (!content)
return false;
if (content->IsHTML())
return content->HasAttr(kNameSpaceID_None, aAtom);
// For XML/XUL elements, an attribute must be equal to the literal
// string "true" to be counted as true. An empty string should _not_
// be counted as true.
return content->AttrValueIs(kNameSpaceID_None, aAtom,
NS_LITERAL_STRING("true"), eCaseMatters);
}
/* static */
int32_t
nsNativeTheme::CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, int32_t defaultValue)
{
if (!aFrame)
return defaultValue;
nsAutoString attr;
aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attr);
nsresult err;
int32_t value = attr.ToInteger(&err);
if (attr.IsEmpty() || NS_FAILED(err))
return defaultValue;
return value;
}
/* static */
double
nsNativeTheme::GetProgressValue(nsIFrame* aFrame)
{
// When we are using the HTML progress element,
// we can get the value from the IDL property.
if (aFrame) {
nsCOMPtr<nsIDOMHTMLProgressElement> progress =
do_QueryInterface(aFrame->GetContent());
if (progress) {
double value;
progress->GetValue(&value);
return value;
}
}
return (double)nsNativeTheme::CheckIntAttr(aFrame, nsGkAtoms::value, 0);
}
/* static */
double
nsNativeTheme::GetProgressMaxValue(nsIFrame* aFrame)
{
// When we are using the HTML progress element,
// we can get the max from the IDL property.
if (aFrame) {
nsCOMPtr<nsIDOMHTMLProgressElement> progress =
do_QueryInterface(aFrame->GetContent());
if (progress) {
double max;
progress->GetMax(&max);
return max;
}
}
return (double)std::max(nsNativeTheme::CheckIntAttr(aFrame, nsGkAtoms::max, 100), 1);
}
bool
nsNativeTheme::GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected)
{
if (!aFrame)
return false;
nsIContent* content = aFrame->GetContent();
if (content->IsXUL()) {
// For a XUL checkbox or radio button, the state of the parent determines
// the checked state
aFrame = aFrame->GetParent();
} else {
// Check for an HTML input element
nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(content);
if (inputElt) {
bool checked;
inputElt->GetChecked(&checked);
return checked;
}
}
return CheckBooleanAttr(aFrame, aCheckSelected ? nsGkAtoms::selected
: nsGkAtoms::checked);
}
bool
nsNativeTheme::IsButtonTypeMenu(nsIFrame* aFrame)
{
if (!aFrame)
return false;
nsIContent* content = aFrame->GetContent();
return content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("menu"), eCaseMatters);
}
bool
nsNativeTheme::IsPressedButton(nsIFrame* aFrame)
{
nsEventStates eventState = GetContentState(aFrame, NS_THEME_TOOLBAR_BUTTON);
if (IsDisabled(aFrame, eventState))
return false;
return IsOpenButton(aFrame) ||
eventState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER);
}
bool
nsNativeTheme::GetIndeterminate(nsIFrame* aFrame)
{
if (!aFrame)
return false;
nsIContent* content = aFrame->GetContent();
if (content->IsXUL()) {
// For a XUL checkbox or radio button, the state of the parent determines
// the state
return CheckBooleanAttr(aFrame->GetParent(), nsGkAtoms::indeterminate);
}
// Check for an HTML input element
nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(content);
if (inputElt) {
bool indeterminate;
inputElt->GetIndeterminate(&indeterminate);
return indeterminate;
}
return false;
}
bool
nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
uint8_t aWidgetType)
{
// Check for specific widgets to see if HTML has overridden the style.
if (!aFrame)
return false;
// Resizers have some special handling, dependent on whether in a scrollable
// container or not. If so, use the scrollable container's to determine
// whether the style is overriden instead of the resizer. This allows a
// non-native transparent resizer to be used instead. Otherwise, we just
// fall through and return false.
if (aWidgetType == NS_THEME_RESIZER) {
nsIFrame* parentFrame = aFrame->GetParent();
if (parentFrame && parentFrame->GetType() == nsGkAtoms::scrollFrame) {
// if the parent is a scrollframe, the resizer should be native themed
// only if the scrollable area doesn't override the widget style.
parentFrame = parentFrame->GetParent();
if (parentFrame) {
return IsWidgetStyled(aPresContext, parentFrame,
parentFrame->StyleDisplay()->mAppearance);
}
}
}
/**
* Progress bar appearance should be the same for the bar and the container
* frame. nsProgressFrame owns the logic and will tell us what we should do.
*/
if (aWidgetType == NS_THEME_PROGRESSBAR_CHUNK ||
aWidgetType == NS_THEME_PROGRESSBAR) {
nsProgressFrame* progressFrame = do_QueryFrame(aWidgetType == NS_THEME_PROGRESSBAR_CHUNK
? aFrame->GetParent() : aFrame);
if (progressFrame) {
return !progressFrame->ShouldUseNativeStyle();
}
}
/**
* Meter bar appearance should be the same for the bar and the container
* frame. nsMeterFrame owns the logic and will tell us what we should do.
*/
if (aWidgetType == NS_THEME_METERBAR_CHUNK ||
aWidgetType == NS_THEME_METERBAR) {
nsMeterFrame* meterFrame = do_QueryFrame(aWidgetType == NS_THEME_METERBAR_CHUNK
? aFrame->GetParent() : aFrame);
if (meterFrame) {
return !meterFrame->ShouldUseNativeStyle();
}
}
/**
* An nsRangeFrame and its children are treated atomically when it
* comes to native theming (either all parts, or no parts, are themed).
* nsRangeFrame owns the logic and will tell us what we should do.
*/
if (aWidgetType == NS_THEME_RANGE ||
aWidgetType == NS_THEME_RANGE_THUMB) {
nsRangeFrame* rangeFrame =
do_QueryFrame(aWidgetType == NS_THEME_RANGE_THUMB
? aFrame->GetParent() : aFrame);
if (rangeFrame) {
return !rangeFrame->ShouldUseNativeStyle();
}
}
return (aWidgetType == NS_THEME_BUTTON ||
aWidgetType == NS_THEME_TEXTFIELD ||
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
aWidgetType == NS_THEME_LISTBOX ||
aWidgetType == NS_THEME_DROPDOWN) &&
aFrame->GetContent()->IsHTML() &&
aPresContext->HasAuthorSpecifiedRules(aFrame,
NS_AUTHOR_SPECIFIED_BORDER |
NS_AUTHOR_SPECIFIED_BACKGROUND);
}
bool
nsNativeTheme::IsDisabled(nsIFrame* aFrame, nsEventStates aEventStates)
{
if (!aFrame) {
return false;
}
nsIContent* content = aFrame->GetContent();
if (!content) {
return false;
}
if (content->IsHTML()) {
return aEventStates.HasState(NS_EVENT_STATE_DISABLED);
}
// For XML/XUL elements, an attribute must be equal to the literal
// string "true" to be counted as true. An empty string should _not_
// be counted as true.
return content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
NS_LITERAL_STRING("true"), eCaseMatters);
}
bool
nsNativeTheme::IsFrameRTL(nsIFrame* aFrame)
{
return aFrame && aFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
}
bool
nsNativeTheme::IsHTMLContent(nsIFrame *aFrame)
{
if (!aFrame) {
return false;
}
nsIContent* content = aFrame->GetContent();
return content && content->IsHTML();
}
// scrollbar button:
int32_t
nsNativeTheme::GetScrollbarButtonType(nsIFrame* aFrame)
{
if (!aFrame)
return 0;
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::scrollbarDownBottom, &nsGkAtoms::scrollbarDownTop,
&nsGkAtoms::scrollbarUpBottom, &nsGkAtoms::scrollbarUpTop,
nullptr};
switch (aFrame->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::sbattr,
strings, eCaseMatters)) {
case 0: return eScrollbarButton_Down | eScrollbarButton_Bottom;
case 1: return eScrollbarButton_Down;
case 2: return eScrollbarButton_Bottom;
case 3: return eScrollbarButton_UpTop;
}
return 0;
}
// treeheadercell:
nsNativeTheme::TreeSortDirection
nsNativeTheme::GetTreeSortDirection(nsIFrame* aFrame)
{
if (!aFrame || !aFrame->GetContent())
return eTreeSortDirection_Natural;
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::descending, &nsGkAtoms::ascending, nullptr};
switch (aFrame->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::sortDirection,
strings, eCaseMatters)) {
case 0: return eTreeSortDirection_Descending;
case 1: return eTreeSortDirection_Ascending;
}
return eTreeSortDirection_Natural;
}
bool
nsNativeTheme::IsLastTreeHeaderCell(nsIFrame* aFrame)
{
if (!aFrame)
return false;
// A tree column picker is always the last header cell.
if (aFrame->GetContent()->Tag() == nsGkAtoms::treecolpicker)
return true;
// Find the parent tree.
nsIContent* parent = aFrame->GetContent()->GetParent();
while (parent && parent->Tag() != nsGkAtoms::tree) {
parent = parent->GetParent();
}
// If the column picker is visible, this can't be the last column.
if (parent && !parent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidecolumnpicker,
NS_LITERAL_STRING("true"), eCaseMatters))
return false;
while ((aFrame = aFrame->GetNextSibling())) {
if (aFrame->GetRect().width > 0)
return false;
}
return true;
}
// tab:
bool
nsNativeTheme::IsBottomTab(nsIFrame* aFrame)
{
if (!aFrame)
return false;
nsAutoString classStr;
aFrame->GetContent()->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, classStr);
return !classStr.IsEmpty() && classStr.Find("tab-bottom") != kNotFound;
}
bool
nsNativeTheme::IsFirstTab(nsIFrame* aFrame)
{
if (!aFrame)
return false;
nsIFrame* first = aFrame->GetParent()->GetFirstPrincipalChild();
while (first) {
if (first->GetRect().width > 0 && first->GetContent()->Tag() == nsGkAtoms::tab)
return (first == aFrame);
first = first->GetNextSibling();
}
return false;
}
bool
nsNativeTheme::IsHorizontal(nsIFrame* aFrame)
{
if (!aFrame)
return false;
return !aFrame->GetContent()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
nsGkAtoms::vertical,
eCaseMatters);
}
bool
nsNativeTheme::IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset)
{
if (!aFrame)
return false;
if (aOffset == 0)
return IsSelectedTab(aFrame);
int32_t thisTabIndex = -1, selectedTabIndex = -1;
nsIFrame* currentTab = aFrame->GetParent()->GetFirstPrincipalChild();
for (int32_t i = 0; currentTab; currentTab = currentTab->GetNextSibling()) {
if (currentTab->GetRect().width == 0)
continue;
if (aFrame == currentTab)
thisTabIndex = i;
if (IsSelectedTab(currentTab))
selectedTabIndex = i;
++i;
}
if (thisTabIndex == -1 || selectedTabIndex == -1)
return false;
return (thisTabIndex - selectedTabIndex == aOffset);
}
// progressbar:
bool
nsNativeTheme::IsIndeterminateProgress(nsIFrame* aFrame,
nsEventStates aEventStates)
{
if (!aFrame || !aFrame->GetContent())
return false;
if (aFrame->GetContent()->IsHTML(nsGkAtoms::progress)) {
return aEventStates.HasState(NS_EVENT_STATE_INDETERMINATE);
}
return aFrame->GetContent()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mode,
NS_LITERAL_STRING("undetermined"),
eCaseMatters);
}
bool
nsNativeTheme::IsVerticalProgress(nsIFrame* aFrame)
{
return aFrame &&
aFrame->StyleDisplay()->mOrient == NS_STYLE_ORIENT_VERTICAL;
}
bool
nsNativeTheme::IsVerticalMeter(nsIFrame* aFrame)
{
NS_PRECONDITION(aFrame, "You have to pass a non-null aFrame");
return aFrame->StyleDisplay()->mOrient == NS_STYLE_ORIENT_VERTICAL;
}
// menupopup:
bool
nsNativeTheme::IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent)
{
if (!aFrame)
return false;
nsIContent* parentContent = aFrame->GetContent()->GetParent();
if (!parentContent || parentContent->Tag() != nsGkAtoms::menu)
return false;
nsIFrame* parent = aFrame;
while ((parent = parent->GetParent())) {
if (parent->GetContent() == parentContent) {
if (aLeftOfParent) {
nsIntRect selfBounds, parentBounds;
aFrame->GetNearestWidget()->GetScreenBounds(selfBounds);
parent->GetNearestWidget()->GetScreenBounds(parentBounds);
*aLeftOfParent = selfBounds.x < parentBounds.x;
}
return true;
}
}
return false;
}
bool
nsNativeTheme::IsRegularMenuItem(nsIFrame *aFrame)
{
nsMenuFrame *menuFrame = do_QueryFrame(aFrame);
return !(menuFrame && (menuFrame->IsOnMenuBar() ||
menuFrame->GetParentMenuListType() != eNotMenuList));
}
bool
nsNativeTheme::IsMenuListEditable(nsIFrame *aFrame)
{
bool isEditable = false;
nsCOMPtr<nsIDOMXULMenuListElement> menulist = do_QueryInterface(aFrame->GetContent());
if (menulist)
menulist->GetEditable(&isEditable);
return isEditable;
}
bool
nsNativeTheme::QueueAnimatedContentForRefresh(nsIContent* aContent,
uint32_t aMinimumFrameRate)
{
NS_ASSERTION(aContent, "Null pointer!");
NS_ASSERTION(aMinimumFrameRate, "aMinimumFrameRate must be non-zero!");
NS_ASSERTION(aMinimumFrameRate <= 1000,
"aMinimumFrameRate must be less than 1000!");
uint32_t timeout = 1000 / aMinimumFrameRate;
timeout = std::min(mAnimatedContentTimeout, timeout);
if (!mAnimatedContentTimer) {
mAnimatedContentTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
NS_ENSURE_TRUE(mAnimatedContentTimer, false);
}
if (mAnimatedContentList.IsEmpty() || timeout != mAnimatedContentTimeout) {
nsresult rv;
if (!mAnimatedContentList.IsEmpty()) {
rv = mAnimatedContentTimer->Cancel();
NS_ENSURE_SUCCESS(rv, false);
}
rv = mAnimatedContentTimer->InitWithCallback(this, timeout,
nsITimer::TYPE_ONE_SHOT);
NS_ENSURE_SUCCESS(rv, false);
mAnimatedContentTimeout = timeout;
}
if (!mAnimatedContentList.AppendElement(aContent)) {
NS_WARNING("Out of memory!");
return false;
}
return true;
}
NS_IMETHODIMP
nsNativeTheme::Notify(nsITimer* aTimer)
{
NS_ASSERTION(aTimer == mAnimatedContentTimer, "Wrong timer!");
// XXX Assumes that calling nsIFrame::Invalidate won't reenter
// QueueAnimatedContentForRefresh.
uint32_t count = mAnimatedContentList.Length();
for (uint32_t index = 0; index < count; index++) {
nsIFrame* frame = mAnimatedContentList[index]->GetPrimaryFrame();
if (frame) {
frame->InvalidateFrame();
}
}
mAnimatedContentList.Clear();
mAnimatedContentTimeout = UINT32_MAX;
return NS_OK;
}
nsIFrame*
nsNativeTheme::GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
bool aNextSibling)
{
if (!aFrame)
return nullptr;
// Find the next visible sibling.
nsIFrame* sibling = aFrame;
do {
sibling = aNextSibling ? sibling->GetNextSibling() : sibling->GetPrevSibling();
} while (sibling && sibling->GetRect().width == 0);
// Check same appearance and adjacency.
if (!sibling ||
sibling->StyleDisplay()->mAppearance != aFrame->StyleDisplay()->mAppearance ||
(sibling->GetRect().XMost() != aFrame->GetRect().x &&
aFrame->GetRect().XMost() != sibling->GetRect().x))
return nullptr;
return sibling;
}
bool
nsNativeTheme::IsRangeHorizontal(nsIFrame* aFrame)
{
nsIFrame* rangeFrame = aFrame;
if (rangeFrame->GetType() != nsGkAtoms::rangeFrame) {
rangeFrame = aFrame->GetParent();
}
MOZ_ASSERT(rangeFrame->GetType() == nsGkAtoms::rangeFrame);
return static_cast<nsRangeFrame*>(rangeFrame)->IsHorizontal();
}
bool
nsNativeTheme::IsDarkBackground(nsIFrame* aFrame)
{
nsIScrollableFrame* scrollFrame = nullptr;
while (!scrollFrame && aFrame) {
scrollFrame = aFrame->GetScrollTargetFrame();
aFrame = aFrame->GetParent();
}
if (!scrollFrame)
return false;
nsIFrame* frame = scrollFrame->GetScrolledFrame();
nsStyleContext* bgSC;
if (nsCSSRendering::FindBackground(frame, &bgSC)) {
nscolor bgColor = bgSC->StyleBackground()->mBackgroundColor;
// Consider the background color dark if the sum of the r, g and b values is
// less than 384 in a semi-transparent document. This heuristic matches what
// WebKit does, and we can improve it later if needed.
return NS_GET_A(bgColor) > 127 &&
NS_GET_R(bgColor) + NS_GET_G(bgColor) + NS_GET_B(bgColor) < 384;
}
return false;
}