Bug 1705532 use async/await instead of callbacks r=annyG
[gecko.git] / widget / nsNativeTheme.cpp
blob9e5fb8eafaf4aa04eabe28c9a0b5ff5aec8b2640
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsNativeTheme.h"
7 #include "nsIWidget.h"
8 #include "mozilla/dom/Document.h"
9 #include "nsIContent.h"
10 #include "nsIFrame.h"
11 #include "nsIScrollableFrame.h"
12 #include "nsLayoutUtils.h"
13 #include "nsNumberControlFrame.h"
14 #include "nsPresContext.h"
15 #include "nsString.h"
16 #include "nsNameSpaceManager.h"
17 #include "nsStyleConsts.h"
18 #include "nsPIDOMWindow.h"
19 #include "nsProgressFrame.h"
20 #include "nsMeterFrame.h"
21 #include "nsMenuFrame.h"
22 #include "nsRangeFrame.h"
23 #include "nsCSSRendering.h"
24 #include "ImageContainer.h"
25 #include "mozilla/ComputedStyle.h"
26 #include "mozilla/EventStates.h"
27 #include "mozilla/dom/Element.h"
28 #include "mozilla/dom/HTMLBodyElement.h"
29 #include "mozilla/dom/HTMLInputElement.h"
30 #include "mozilla/dom/HTMLProgressElement.h"
31 #include "mozilla/PresShell.h"
32 #include "mozilla/StaticPrefs_layout.h"
33 #include "mozilla/dom/DocumentInlines.h"
34 #include "mozilla/RelativeLuminanceUtils.h"
35 #include <algorithm>
37 using namespace mozilla;
38 using namespace mozilla::dom;
40 nsNativeTheme::nsNativeTheme() : mAnimatedContentTimeout(UINT32_MAX) {}
42 NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed)
44 /* static */ EventStates nsNativeTheme::GetContentState(
45 nsIFrame* aFrame, StyleAppearance aAppearance) {
46 if (!aFrame) {
47 return EventStates();
50 nsIContent* frameContent = aFrame->GetContent();
51 if (!frameContent || !frameContent->IsElement()) {
52 return EventStates();
55 const bool isXULElement = frameContent->IsXULElement();
56 if (isXULElement) {
57 if (aAppearance == StyleAppearance::CheckboxLabel ||
58 aAppearance == StyleAppearance::RadioLabel) {
59 aFrame = aFrame->GetParent()->GetParent();
60 frameContent = aFrame->GetContent();
61 } else if (aAppearance == StyleAppearance::Checkbox ||
62 aAppearance == StyleAppearance::Radio ||
63 aAppearance == StyleAppearance::ToolbarbuttonDropdown ||
64 aAppearance == StyleAppearance::Treeheadersortarrow ||
65 aAppearance == StyleAppearance::ButtonArrowPrevious ||
66 aAppearance == StyleAppearance::ButtonArrowNext ||
67 aAppearance == StyleAppearance::ButtonArrowUp ||
68 aAppearance == StyleAppearance::ButtonArrowDown) {
69 aFrame = aFrame->GetParent();
70 frameContent = aFrame->GetContent();
72 MOZ_ASSERT(frameContent && frameContent->IsElement());
75 EventStates flags = frameContent->AsElement()->State();
76 nsNumberControlFrame* numberControlFrame =
77 nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
78 if (numberControlFrame &&
79 numberControlFrame->GetContent()->AsElement()->State().HasState(
80 NS_EVENT_STATE_DISABLED)) {
81 flags |= NS_EVENT_STATE_DISABLED;
84 if (!isXULElement) {
85 return flags;
88 if (CheckBooleanAttr(aFrame, nsGkAtoms::disabled)) {
89 flags |= NS_EVENT_STATE_DISABLED;
92 switch (aAppearance) {
93 case StyleAppearance::RadioLabel:
94 case StyleAppearance::Radio: {
95 if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) {
96 flags |= NS_EVENT_STATE_FOCUS;
97 nsPIDOMWindowOuter* window =
98 aFrame->GetContent()->OwnerDoc()->GetWindow();
99 if (window && window->ShouldShowFocusRing()) {
100 flags |= NS_EVENT_STATE_FOCUSRING;
103 if (CheckBooleanAttr(aFrame, nsGkAtoms::selected)) {
104 flags |= NS_EVENT_STATE_CHECKED;
106 break;
108 case StyleAppearance::CheckboxLabel:
109 case StyleAppearance::Checkbox: {
110 if (CheckBooleanAttr(aFrame, nsGkAtoms::checked)) {
111 flags |= NS_EVENT_STATE_CHECKED;
112 } else if (CheckBooleanAttr(aFrame, nsGkAtoms::indeterminate)) {
113 flags |= NS_EVENT_STATE_INDETERMINATE;
115 break;
117 case StyleAppearance::MenulistButton:
118 case StyleAppearance::Menulist:
119 case StyleAppearance::NumberInput:
120 case StyleAppearance::Textfield:
121 case StyleAppearance::Searchfield:
122 case StyleAppearance::Textarea: {
123 if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) {
124 flags |= NS_EVENT_STATE_FOCUS | NS_EVENT_STATE_FOCUSRING;
126 break;
128 default:
129 break;
132 return flags;
135 /* static */
136 bool nsNativeTheme::CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom) {
137 if (!aFrame) return false;
139 nsIContent* content = aFrame->GetContent();
140 if (!content || !content->IsElement()) return false;
142 if (content->IsHTMLElement())
143 return content->AsElement()->HasAttr(kNameSpaceID_None, aAtom);
145 // For XML/XUL elements, an attribute must be equal to the literal
146 // string "true" to be counted as true. An empty string should _not_
147 // be counted as true.
148 return content->AsElement()->AttrValueIs(kNameSpaceID_None, aAtom, u"true"_ns,
149 eCaseMatters);
152 /* static */
153 int32_t nsNativeTheme::CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom,
154 int32_t defaultValue) {
155 if (!aFrame) return defaultValue;
157 nsIContent* content = aFrame->GetContent();
158 if (!content || !content->IsElement()) return defaultValue;
160 nsAutoString attr;
161 content->AsElement()->GetAttr(kNameSpaceID_None, aAtom, attr);
162 nsresult err;
163 int32_t value = attr.ToInteger(&err);
164 if (attr.IsEmpty() || NS_FAILED(err)) return defaultValue;
166 return value;
169 /* static */
170 double nsNativeTheme::GetProgressValue(nsIFrame* aFrame) {
171 if (!aFrame || !aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
172 return 0;
175 return static_cast<HTMLProgressElement*>(aFrame->GetContent())->Value();
178 /* static */
179 double nsNativeTheme::GetProgressMaxValue(nsIFrame* aFrame) {
180 if (!aFrame || !aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
181 return 100;
184 return static_cast<HTMLProgressElement*>(aFrame->GetContent())->Max();
187 bool nsNativeTheme::IsButtonTypeMenu(nsIFrame* aFrame) {
188 if (!aFrame) return false;
190 nsIContent* content = aFrame->GetContent();
191 return content->IsXULElement(nsGkAtoms::button) &&
192 content->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
193 u"menu"_ns, eCaseMatters);
196 bool nsNativeTheme::IsPressedButton(nsIFrame* aFrame) {
197 EventStates eventState =
198 GetContentState(aFrame, StyleAppearance::Toolbarbutton);
199 if (eventState.HasState(NS_EVENT_STATE_DISABLED)) return false;
201 return IsOpenButton(aFrame) ||
202 eventState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER);
205 bool nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext,
206 nsIFrame* aFrame,
207 StyleAppearance aAppearance) {
208 // Check for specific widgets to see if HTML has overridden the style.
209 if (!aFrame) {
210 return false;
213 // Resizers have some special handling, dependent on whether in a scrollable
214 // container or not. If so, use the scrollable container's to determine
215 // whether the style is overriden instead of the resizer. This allows a
216 // non-native transparent resizer to be used instead. Otherwise, we just
217 // fall through and return false.
218 if (aAppearance == StyleAppearance::Resizer) {
219 nsIFrame* parentFrame = aFrame->GetParent();
220 if (parentFrame && parentFrame->IsScrollFrame()) {
221 // if the parent is a scrollframe, the resizer should be native themed
222 // only if the scrollable area doesn't override the widget style.
224 // note that the condition below looks a bit suspect but it's the right
225 // one. If there's no valid appearance, then we should return true, it's
226 // effectively the same as if it had overridden the appearance.
227 parentFrame = parentFrame->GetParent();
228 if (!parentFrame) {
229 return false;
231 auto parentAppearance =
232 parentFrame->StyleDisplay()->EffectiveAppearance();
233 return parentAppearance == StyleAppearance::None ||
234 IsWidgetStyled(aPresContext, parentFrame, parentAppearance);
239 * Progress bar appearance should be the same for the bar and the container
240 * frame. nsProgressFrame owns the logic and will tell us what we should do.
242 if (aAppearance == StyleAppearance::Progresschunk ||
243 aAppearance == StyleAppearance::ProgressBar) {
244 nsProgressFrame* progressFrame = do_QueryFrame(
245 aAppearance == StyleAppearance::Progresschunk ? aFrame->GetParent()
246 : aFrame);
247 if (progressFrame) {
248 return !progressFrame->ShouldUseNativeStyle();
253 * Meter bar appearance should be the same for the bar and the container
254 * frame. nsMeterFrame owns the logic and will tell us what we should do.
256 if (aAppearance == StyleAppearance::Meterchunk ||
257 aAppearance == StyleAppearance::Meter) {
258 nsMeterFrame* meterFrame = do_QueryFrame(
259 aAppearance == StyleAppearance::Meterchunk ? aFrame->GetParent()
260 : aFrame);
261 if (meterFrame) {
262 return !meterFrame->ShouldUseNativeStyle();
267 * An nsRangeFrame and its children are treated atomically when it
268 * comes to native theming (either all parts, or no parts, are themed).
269 * nsRangeFrame owns the logic and will tell us what we should do.
271 if (aAppearance == StyleAppearance::Range ||
272 aAppearance == StyleAppearance::RangeThumb) {
273 nsRangeFrame* rangeFrame = do_QueryFrame(
274 aAppearance == StyleAppearance::RangeThumb ? aFrame->GetParent()
275 : aFrame);
276 if (rangeFrame) {
277 return !rangeFrame->ShouldUseNativeStyle();
281 return nsLayoutUtils::AuthorSpecifiedBorderBackgroundDisablesTheming(
282 aAppearance) &&
283 aFrame->GetContent()->IsHTMLElement() &&
284 aFrame->Style()->HasAuthorSpecifiedBorderOrBackground();
287 /* static */
288 bool nsNativeTheme::IsFrameRTL(nsIFrame* aFrame) {
289 if (!aFrame) {
290 return false;
292 return aFrame->GetWritingMode().IsPhysicalRTL();
295 /* static */
296 bool nsNativeTheme::IsHTMLContent(nsIFrame* aFrame) {
297 if (!aFrame) {
298 return false;
300 nsIContent* content = aFrame->GetContent();
301 return content && content->IsHTMLElement();
304 // scrollbar button:
305 int32_t nsNativeTheme::GetScrollbarButtonType(nsIFrame* aFrame) {
306 if (!aFrame) return 0;
308 static Element::AttrValuesArray strings[] = {
309 nsGkAtoms::scrollbarDownBottom, nsGkAtoms::scrollbarDownTop,
310 nsGkAtoms::scrollbarUpBottom, nsGkAtoms::scrollbarUpTop, nullptr};
312 nsIContent* content = aFrame->GetContent();
313 if (!content || !content->IsElement()) {
314 return 0;
317 switch (content->AsElement()->FindAttrValueIn(
318 kNameSpaceID_None, nsGkAtoms::sbattr, strings, eCaseMatters)) {
319 case 0:
320 return eScrollbarButton_Down | eScrollbarButton_Bottom;
321 case 1:
322 return eScrollbarButton_Down;
323 case 2:
324 return eScrollbarButton_Bottom;
325 case 3:
326 return eScrollbarButton_UpTop;
329 return 0;
332 // treeheadercell:
333 nsNativeTheme::TreeSortDirection nsNativeTheme::GetTreeSortDirection(
334 nsIFrame* aFrame) {
335 if (!aFrame || !aFrame->GetContent()) return eTreeSortDirection_Natural;
337 static Element::AttrValuesArray strings[] = {nsGkAtoms::descending,
338 nsGkAtoms::ascending, nullptr};
340 nsIContent* content = aFrame->GetContent();
341 if (content->IsElement()) {
342 switch (content->AsElement()->FindAttrValueIn(
343 kNameSpaceID_None, nsGkAtoms::sortDirection, strings, eCaseMatters)) {
344 case 0:
345 return eTreeSortDirection_Descending;
346 case 1:
347 return eTreeSortDirection_Ascending;
351 return eTreeSortDirection_Natural;
354 bool nsNativeTheme::IsLastTreeHeaderCell(nsIFrame* aFrame) {
355 if (!aFrame) return false;
357 // A tree column picker is always the last header cell.
358 if (aFrame->GetContent()->IsXULElement(nsGkAtoms::treecolpicker)) return true;
360 // Find the parent tree.
361 nsIContent* parent = aFrame->GetContent()->GetParent();
362 while (parent && !parent->IsXULElement(nsGkAtoms::tree)) {
363 parent = parent->GetParent();
366 // If the column picker is visible, this can't be the last column.
367 if (parent && !parent->AsElement()->AttrValueIs(kNameSpaceID_None,
368 nsGkAtoms::hidecolumnpicker,
369 u"true"_ns, eCaseMatters))
370 return false;
372 while ((aFrame = aFrame->GetNextSibling())) {
373 if (aFrame->GetRect().Width() > 0) return false;
375 return true;
378 // tab:
379 bool nsNativeTheme::IsBottomTab(nsIFrame* aFrame) {
380 if (!aFrame) return false;
382 nsAutoString classStr;
383 if (aFrame->GetContent()->IsElement()) {
384 aFrame->GetContent()->AsElement()->GetAttr(kNameSpaceID_None,
385 nsGkAtoms::_class, classStr);
387 // FIXME: This looks bogus, shouldn't this be looking at GetClasses()?
388 return !classStr.IsEmpty() && classStr.Find("tab-bottom") != kNotFound;
391 bool nsNativeTheme::IsFirstTab(nsIFrame* aFrame) {
392 if (!aFrame) return false;
394 for (nsIFrame* first : aFrame->GetParent()->PrincipalChildList()) {
395 if (first->GetRect().Width() > 0 &&
396 first->GetContent()->IsXULElement(nsGkAtoms::tab))
397 return (first == aFrame);
399 return false;
402 bool nsNativeTheme::IsHorizontal(nsIFrame* aFrame) {
403 if (!aFrame) return false;
405 if (!aFrame->GetContent()->IsElement()) return true;
407 return !aFrame->GetContent()->AsElement()->AttrValueIs(
408 kNameSpaceID_None, nsGkAtoms::orient, nsGkAtoms::vertical, eCaseMatters);
411 bool nsNativeTheme::IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset) {
412 if (!aFrame) return false;
414 if (aOffset == 0) return IsSelectedTab(aFrame);
416 int32_t thisTabIndex = -1, selectedTabIndex = -1;
418 nsIFrame* currentTab = aFrame->GetParent()->PrincipalChildList().FirstChild();
419 for (int32_t i = 0; currentTab; currentTab = currentTab->GetNextSibling()) {
420 if (currentTab->GetRect().Width() == 0) continue;
421 if (aFrame == currentTab) thisTabIndex = i;
422 if (IsSelectedTab(currentTab)) selectedTabIndex = i;
423 ++i;
426 if (thisTabIndex == -1 || selectedTabIndex == -1) return false;
428 return (thisTabIndex - selectedTabIndex == aOffset);
431 bool nsNativeTheme::IsVerticalProgress(nsIFrame* aFrame) {
432 if (!aFrame) {
433 return false;
435 return IsVerticalMeter(aFrame);
438 bool nsNativeTheme::IsVerticalMeter(nsIFrame* aFrame) {
439 MOZ_ASSERT(aFrame, "You have to pass a non-null aFrame");
440 switch (aFrame->StyleDisplay()->mOrient) {
441 case StyleOrient::Horizontal:
442 return false;
443 case StyleOrient::Vertical:
444 return true;
445 case StyleOrient::Inline:
446 return aFrame->GetWritingMode().IsVertical();
447 case StyleOrient::Block:
448 return !aFrame->GetWritingMode().IsVertical();
450 MOZ_ASSERT_UNREACHABLE("unexpected -moz-orient value");
451 return false;
454 // menupopup:
455 bool nsNativeTheme::IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent) {
456 if (!aFrame) return false;
458 nsIContent* parentContent = aFrame->GetContent()->GetParent();
459 if (!parentContent || !parentContent->IsXULElement(nsGkAtoms::menu))
460 return false;
462 nsIFrame* parent = aFrame;
463 while ((parent = parent->GetParent())) {
464 if (parent->GetContent() == parentContent) {
465 if (aLeftOfParent) {
466 LayoutDeviceIntRect selfBounds, parentBounds;
467 selfBounds = aFrame->GetNearestWidget()->GetScreenBounds();
468 parentBounds = parent->GetNearestWidget()->GetScreenBounds();
469 *aLeftOfParent = selfBounds.X() < parentBounds.X();
471 return true;
475 return false;
478 bool nsNativeTheme::IsRegularMenuItem(nsIFrame* aFrame) {
479 nsMenuFrame* menuFrame = do_QueryFrame(aFrame);
480 return !(menuFrame &&
481 (menuFrame->IsOnMenuBar() || menuFrame->IsParentMenuList()));
484 bool nsNativeTheme::QueueAnimatedContentForRefresh(nsIContent* aContent,
485 uint32_t aMinimumFrameRate) {
486 NS_ASSERTION(aContent, "Null pointer!");
487 NS_ASSERTION(aMinimumFrameRate, "aMinimumFrameRate must be non-zero!");
488 NS_ASSERTION(aMinimumFrameRate <= 1000,
489 "aMinimumFrameRate must be less than 1000!");
491 uint32_t timeout = 1000 / aMinimumFrameRate;
492 timeout = std::min(mAnimatedContentTimeout, timeout);
494 if (!mAnimatedContentTimer) {
495 mAnimatedContentTimer = NS_NewTimer();
496 NS_ENSURE_TRUE(mAnimatedContentTimer, false);
499 if (mAnimatedContentList.IsEmpty() || timeout != mAnimatedContentTimeout) {
500 nsresult rv;
501 if (!mAnimatedContentList.IsEmpty()) {
502 rv = mAnimatedContentTimer->Cancel();
503 NS_ENSURE_SUCCESS(rv, false);
506 if (XRE_IsContentProcess() && NS_IsMainThread()) {
507 mAnimatedContentTimer->SetTarget(
508 aContent->OwnerDoc()->EventTargetFor(TaskCategory::Other));
510 rv = mAnimatedContentTimer->InitWithCallback(this, timeout,
511 nsITimer::TYPE_ONE_SHOT);
512 NS_ENSURE_SUCCESS(rv, false);
514 mAnimatedContentTimeout = timeout;
517 // XXX(Bug 1631371) Check if this should use a fallible operation as it
518 // pretended earlier.
519 mAnimatedContentList.AppendElement(aContent);
521 return true;
524 NS_IMETHODIMP
525 nsNativeTheme::Notify(nsITimer* aTimer) {
526 NS_ASSERTION(aTimer == mAnimatedContentTimer, "Wrong timer!");
528 // XXX Assumes that calling nsIFrame::Invalidate won't reenter
529 // QueueAnimatedContentForRefresh.
531 uint32_t count = mAnimatedContentList.Length();
532 for (uint32_t index = 0; index < count; index++) {
533 nsIFrame* frame = mAnimatedContentList[index]->GetPrimaryFrame();
534 if (frame) {
535 frame->InvalidateFrame();
539 mAnimatedContentList.Clear();
540 mAnimatedContentTimeout = UINT32_MAX;
541 return NS_OK;
544 NS_IMETHODIMP
545 nsNativeTheme::GetName(nsACString& aName) {
546 aName.AssignLiteral("nsNativeTheme");
547 return NS_OK;
550 nsIFrame* nsNativeTheme::GetAdjacentSiblingFrameWithSameAppearance(
551 nsIFrame* aFrame, bool aNextSibling) {
552 if (!aFrame) return nullptr;
554 // Find the next visible sibling.
555 nsIFrame* sibling = aFrame;
556 do {
557 sibling =
558 aNextSibling ? sibling->GetNextSibling() : sibling->GetPrevSibling();
559 } while (sibling && sibling->GetRect().Width() == 0);
561 // Check same appearance and adjacency.
562 if (!sibling ||
563 sibling->StyleDisplay()->EffectiveAppearance() !=
564 aFrame->StyleDisplay()->EffectiveAppearance() ||
565 (sibling->GetRect().XMost() != aFrame->GetRect().X() &&
566 aFrame->GetRect().XMost() != sibling->GetRect().X()))
567 return nullptr;
568 return sibling;
571 bool nsNativeTheme::IsRangeHorizontal(nsIFrame* aFrame) {
572 nsIFrame* rangeFrame = aFrame;
573 if (!rangeFrame->IsRangeFrame()) {
574 // If the thumb's frame is passed in, get its range parent:
575 rangeFrame = aFrame->GetParent();
577 if (rangeFrame->IsRangeFrame()) {
578 return static_cast<nsRangeFrame*>(rangeFrame)->IsHorizontal();
580 // Not actually a range frame - just use the ratio of the frame's size to
581 // decide:
582 return aFrame->GetSize().width >= aFrame->GetSize().height;
585 static nsIFrame* GetBodyFrame(nsIFrame* aCanvasFrame) {
586 nsIContent* body = aCanvasFrame->PresContext()->Document()->GetBodyElement();
587 if (!body) {
588 return nullptr;
590 return body->GetPrimaryFrame();
593 bool nsNativeTheme::IsDarkColor(nscolor aColor) {
594 // Given https://www.w3.org/TR/WCAG20/#contrast-ratiodef, this is the
595 // threshold that tells us whether contrast is better against white or black.
597 // Contrast ratio against black is: (L + 0.05) / 0.05
598 // Contrast ratio against white is: 1.05 / (L + 0.05)
600 // So the intersection is:
602 // (L + 0.05) / 0.05 = 1.05 / (L + 0.05)
604 // And the solution to that equation is:
606 // sqrt(1.05 * 0.05) - 0.05
608 // So we consider a color dark if the contrast is below this threshold, and
609 // it's at least half-opaque.
610 constexpr float kThreshold = 0.179129;
611 return NS_GET_A(aColor) > 127 &&
612 RelativeLuminanceUtils::Compute(aColor) < kThreshold;
615 /* static */
616 bool nsNativeTheme::IsDarkBackground(nsIFrame* aFrame) {
617 // Try to find the scrolled frame. Note that for stuff like xul <tree> there
618 // might be none.
620 nsIFrame* frame = aFrame;
621 nsIScrollableFrame* scrollFrame = nullptr;
622 while (!scrollFrame && frame) {
623 scrollFrame = frame->GetScrollTargetFrame();
624 frame = frame->GetParent();
626 if (scrollFrame) {
627 aFrame = scrollFrame->GetScrolledFrame();
628 } else {
629 // Leave aFrame untouched.
633 auto backgroundFrame = nsCSSRendering::FindNonTransparentBackgroundFrame(
634 aFrame, /* aStopAtThemed = */ false);
635 if (!backgroundFrame.mFrame) {
636 return false;
639 nscolor color = backgroundFrame.mFrame->StyleBackground()->BackgroundColor(
640 backgroundFrame.mFrame);
642 if (backgroundFrame.mIsForCanvas) {
643 // For canvas frames, prefer to look at the body first, because the body
644 // background color is most likely what will be visible as the background
645 // color of the page, even if the html element has a different background
646 // color which prevents that of the body frame to propagate to the viewport.
647 if (nsIFrame* bodyFrame = GetBodyFrame(aFrame)) {
648 nscolor bodyColor =
649 bodyFrame->StyleBackground()->BackgroundColor(bodyFrame);
650 if (NS_GET_A(bodyColor)) {
651 color = bodyColor;
656 return IsDarkColor(color);
659 /*static*/
660 bool nsNativeTheme::IsWidgetScrollbarPart(StyleAppearance aAppearance) {
661 switch (aAppearance) {
662 case StyleAppearance::ScrollbarVertical:
663 case StyleAppearance::ScrollbarHorizontal:
664 case StyleAppearance::ScrollbarbuttonUp:
665 case StyleAppearance::ScrollbarbuttonDown:
666 case StyleAppearance::ScrollbarbuttonLeft:
667 case StyleAppearance::ScrollbarbuttonRight:
668 case StyleAppearance::ScrollbarthumbVertical:
669 case StyleAppearance::ScrollbarthumbHorizontal:
670 case StyleAppearance::ScrollbartrackHorizontal:
671 case StyleAppearance::ScrollbartrackVertical:
672 case StyleAppearance::Scrollcorner:
673 return true;
674 default:
675 return false;