2005-08-20 11:13:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2005-08-20 11:13:18 +04:00
|
|
|
|
|
|
|
#include "nsNativeTheme.h"
|
2009-04-02 01:59:02 +04:00
|
|
|
#include "nsIWidget.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2005-08-20 11:13:18 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
2020-09-18 21:32:13 +03:00
|
|
|
#include "nsIScrollableFrame.h"
|
2013-12-05 20:20:34 +04:00
|
|
|
#include "nsNumberControlFrame.h"
|
2005-08-20 11:14:04 +04:00
|
|
|
#include "nsPresContext.h"
|
2005-08-20 11:13:18 +04:00
|
|
|
#include "nsString.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2018-07-25 16:03:45 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2010-04-21 18:53:42 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-05-06 14:00:30 +04:00
|
|
|
#include "nsProgressFrame.h"
|
2012-05-16 20:31:01 +04:00
|
|
|
#include "nsMeterFrame.h"
|
2011-07-11 18:05:07 +04:00
|
|
|
#include "nsMenuFrame.h"
|
2013-03-16 09:40:15 +04:00
|
|
|
#include "nsRangeFrame.h"
|
2013-05-19 19:01:28 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2020-10-01 00:06:47 +03:00
|
|
|
#include "ImageContainer.h"
|
2018-11-14 20:03:36 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-05-31 06:23:49 +04:00
|
|
|
#include "mozilla/dom/HTMLBodyElement.h"
|
2018-02-21 01:10:44 +03:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2013-08-02 02:24:22 +04:00
|
|
|
#include "mozilla/dom/HTMLProgressElement.h"
|
2019-04-03 15:40:26 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/DocumentInlines.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
using namespace mozilla;
|
2013-08-02 02:24:22 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2012-09-28 10:57:33 +04:00
|
|
|
nsNativeTheme::nsNativeTheme() : mAnimatedContentTimeout(UINT32_MAX) {}
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed)
|
2010-11-13 11:19:38 +03:00
|
|
|
|
2020-10-27 18:16:49 +03:00
|
|
|
/* static */ EventStates nsNativeTheme::GetContentState(
|
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
2014-04-03 08:18:36 +04:00
|
|
|
if (!aFrame) return EventStates();
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2018-10-24 18:24:57 +03:00
|
|
|
bool isXULCheckboxRadio = (aAppearance == StyleAppearance::Checkbox ||
|
|
|
|
aAppearance == StyleAppearance::Radio) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aFrame->GetContent()->IsXULElement();
|
2005-08-20 11:13:33 +04:00
|
|
|
if (isXULCheckboxRadio) aFrame = aFrame->GetParent();
|
2005-08-20 11:13:20 +04:00
|
|
|
|
2009-04-14 21:22:04 +04:00
|
|
|
if (!aFrame->GetContent()) return EventStates();
|
|
|
|
|
2011-06-01 05:46:56 +04:00
|
|
|
nsIContent* frameContent = aFrame->GetContent();
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates flags;
|
2011-06-01 05:46:56 +04:00
|
|
|
if (frameContent->IsElement()) {
|
|
|
|
flags = frameContent->AsElement()->State();
|
2013-12-05 20:20:34 +04:00
|
|
|
|
2013-12-11 06:13:06 +04:00
|
|
|
nsNumberControlFrame* numberControlFrame =
|
|
|
|
nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
|
|
|
|
if (numberControlFrame &&
|
|
|
|
numberControlFrame->GetContent()->AsElement()->State().HasState(
|
|
|
|
NS_EVENT_STATE_DISABLED)) {
|
|
|
|
flags |= NS_EVENT_STATE_DISABLED;
|
|
|
|
}
|
2011-06-01 05:46:56 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-05-19 18:46:42 +03:00
|
|
|
if (isXULCheckboxRadio && aAppearance == StyleAppearance::Radio &&
|
|
|
|
IsFocused(aFrame)) {
|
|
|
|
flags |= NS_EVENT_STATE_FOCUS;
|
2020-05-25 10:42:38 +03:00
|
|
|
nsPIDOMWindowOuter* window = aFrame->GetContent()->OwnerDoc()->GetWindow();
|
2020-05-19 18:46:42 +03:00
|
|
|
if (window && window->ShouldShowFocusRing()) {
|
|
|
|
flags |= NS_EVENT_STATE_FOCUSRING;
|
2020-05-16 21:03:54 +03:00
|
|
|
}
|
2005-08-20 11:13:20 +04:00
|
|
|
}
|
2010-04-21 18:53:42 +04:00
|
|
|
|
2005-08-20 11:13:18 +04:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2013-02-25 04:26:07 +04:00
|
|
|
/* static */
|
2017-10-03 01:05:19 +03:00
|
|
|
bool nsNativeTheme::CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2005-08-20 11:13:33 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!content || !content->IsElement()) return false;
|
2009-04-14 21:22:04 +04:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsHTMLElement())
|
2017-12-07 21:13:50 +03:00
|
|
|
return content->AsElement()->HasAttr(kNameSpaceID_None, aAtom);
|
2005-08-20 11:13:18 +04:00
|
|
|
|
|
|
|
// 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.
|
2017-12-07 21:13:50 +03:00
|
|
|
return content->AsElement()->AttrValueIs(kNameSpaceID_None, aAtom, u"true"_ns,
|
|
|
|
eCaseMatters);
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 04:26:07 +04:00
|
|
|
/* static */
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t nsNativeTheme::CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom,
|
|
|
|
int32_t defaultValue) {
|
2008-03-27 08:36:20 +03:00
|
|
|
if (!aFrame) return defaultValue;
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content || !content->IsElement()) return defaultValue;
|
|
|
|
|
2005-08-20 11:13:18 +04:00
|
|
|
nsAutoString attr;
|
2017-12-07 21:13:50 +03:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, aAtom, attr);
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult err;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t value = attr.ToInteger(&err);
|
2008-03-27 08:36:20 +03:00
|
|
|
if (attr.IsEmpty() || NS_FAILED(err)) return defaultValue;
|
2005-08-20 11:13:18 +04:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-02-25 04:26:07 +04:00
|
|
|
/* static */
|
|
|
|
double nsNativeTheme::GetProgressValue(nsIFrame* aFrame) {
|
2018-11-20 17:12:33 +03:00
|
|
|
if (!aFrame || !aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
|
|
|
|
return 0;
|
2013-02-25 04:26:07 +04:00
|
|
|
}
|
|
|
|
|
2018-11-20 17:12:33 +03:00
|
|
|
return static_cast<HTMLProgressElement*>(aFrame->GetContent())->Value();
|
2013-02-25 04:26:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
double nsNativeTheme::GetProgressMaxValue(nsIFrame* aFrame) {
|
2018-11-20 17:12:33 +03:00
|
|
|
if (!aFrame || !aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
|
|
|
|
return 100;
|
2013-02-25 04:26:07 +04:00
|
|
|
}
|
|
|
|
|
2018-11-20 17:12:33 +03:00
|
|
|
return static_cast<HTMLProgressElement*>(aFrame->GetContent())->Max();
|
2013-02-25 04:26:07 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsNativeTheme::GetCheckedOrSelected(nsIFrame* aFrame,
|
|
|
|
bool aCheckSelected) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2005-08-20 11:13:33 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsXULElement()) {
|
2005-08-20 11:13:18 +04:00
|
|
|
// For a XUL checkbox or radio button, the state of the parent determines
|
|
|
|
// the checked state
|
2005-08-20 11:13:33 +04:00
|
|
|
aFrame = aFrame->GetParent();
|
2005-08-20 11:13:18 +04:00
|
|
|
} else {
|
|
|
|
// Check for an HTML input element
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement* inputElt = HTMLInputElement::FromNode(content);
|
2005-08-20 11:13:18 +04:00
|
|
|
if (inputElt) {
|
2018-02-21 01:10:44 +03:00
|
|
|
return inputElt->Checked();
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 22:11:22 +04:00
|
|
|
return CheckBooleanAttr(
|
|
|
|
aFrame, aCheckSelected ? nsGkAtoms::selected : nsGkAtoms::checked);
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
|
|
|
|
2009-08-11 01:23:50 +04:00
|
|
|
bool nsNativeTheme::IsButtonTypeMenu(nsIFrame* aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2009-08-11 01:23:50 +04:00
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2017-02-10 21:20:19 +03:00
|
|
|
return content->IsXULElement(nsGkAtoms::button) &&
|
2017-12-07 21:13:50 +03:00
|
|
|
content->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
u"menu"_ns, eCaseMatters);
|
2009-08-11 01:23:50 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 18:42:45 +04:00
|
|
|
bool nsNativeTheme::IsPressedButton(nsIFrame* aFrame) {
|
2018-07-25 16:03:45 +03:00
|
|
|
EventStates eventState =
|
|
|
|
GetContentState(aFrame, StyleAppearance::Toolbarbutton);
|
2011-08-08 18:42:45 +04:00
|
|
|
if (IsDisabled(aFrame, eventState)) return false;
|
|
|
|
|
|
|
|
return IsOpenButton(aFrame) ||
|
|
|
|
eventState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
|
|
|
|
2009-01-30 10:19:41 +03:00
|
|
|
bool nsNativeTheme::GetIndeterminate(nsIFrame* aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2009-01-30 10:19:41 +03:00
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsXULElement()) {
|
2009-01-30 10:19:41 +03:00
|
|
|
// For a XUL checkbox or radio button, the state of the parent determines
|
|
|
|
// the state
|
2011-10-14 22:11:22 +04:00
|
|
|
return CheckBooleanAttr(aFrame->GetParent(), nsGkAtoms::indeterminate);
|
2009-01-30 10:19:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for an HTML input element
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement* inputElt = HTMLInputElement::FromNode(content);
|
2009-01-30 10:19:41 +03:00
|
|
|
if (inputElt) {
|
2018-02-21 01:10:44 +03:00
|
|
|
return inputElt->Indeterminate();
|
2009-01-30 10:19:41 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-30 10:19:41 +03:00
|
|
|
}
|
|
|
|
|
2005-08-20 11:14:04 +04:00
|
|
|
bool nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
2018-10-24 18:24:57 +03:00
|
|
|
StyleAppearance aAppearance) {
|
2005-08-20 11:13:18 +04:00
|
|
|
// Check for specific widgets to see if HTML has overridden the style.
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2010-06-21 16:37:35 +04:00
|
|
|
|
|
|
|
// 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.
|
2018-10-24 18:24:57 +03:00
|
|
|
if (aAppearance == StyleAppearance::Resizer) {
|
2010-06-21 16:37:35 +04:00
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (parentFrame && parentFrame->IsScrollFrame()) {
|
2010-06-21 16:37:35 +04:00
|
|
|
// 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) {
|
2020-07-17 01:04:12 +03:00
|
|
|
return IsWidgetStyled(
|
|
|
|
aPresContext, parentFrame,
|
|
|
|
parentFrame->StyleDisplay()->EffectiveAppearance());
|
2010-06-21 16:37:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 14:00:30 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-24 18:24:57 +03:00
|
|
|
if (aAppearance == StyleAppearance::Progresschunk ||
|
2018-11-09 06:25:56 +03:00
|
|
|
aAppearance == StyleAppearance::ProgressBar) {
|
2018-10-24 18:24:57 +03:00
|
|
|
nsProgressFrame* progressFrame = do_QueryFrame(
|
|
|
|
aAppearance == StyleAppearance::Progresschunk ? aFrame->GetParent()
|
|
|
|
: aFrame);
|
2011-05-06 14:00:30 +04:00
|
|
|
if (progressFrame) {
|
|
|
|
return !progressFrame->ShouldUseNativeStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 20:31:01 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-24 18:24:57 +03:00
|
|
|
if (aAppearance == StyleAppearance::Meterchunk ||
|
2018-11-09 06:25:56 +03:00
|
|
|
aAppearance == StyleAppearance::Meter) {
|
2018-10-24 18:24:57 +03:00
|
|
|
nsMeterFrame* meterFrame = do_QueryFrame(
|
|
|
|
aAppearance == StyleAppearance::Meterchunk ? aFrame->GetParent()
|
|
|
|
: aFrame);
|
2012-05-16 20:31:01 +04:00
|
|
|
if (meterFrame) {
|
|
|
|
return !meterFrame->ShouldUseNativeStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-16 09:40:15 +04:00
|
|
|
/**
|
2013-03-29 00:25:05 +04:00
|
|
|
* An nsRangeFrame and its children are treated atomically when it
|
|
|
|
* comes to native theming (either all parts, or no parts, are themed).
|
2013-03-16 09:40:15 +04:00
|
|
|
* nsRangeFrame owns the logic and will tell us what we should do.
|
|
|
|
*/
|
2018-10-24 18:24:57 +03:00
|
|
|
if (aAppearance == StyleAppearance::Range ||
|
|
|
|
aAppearance == StyleAppearance::RangeThumb) {
|
2013-03-29 00:25:05 +04:00
|
|
|
nsRangeFrame* rangeFrame = do_QueryFrame(
|
2018-10-24 18:24:57 +03:00
|
|
|
aAppearance == StyleAppearance::RangeThumb ? aFrame->GetParent()
|
2013-03-29 00:25:05 +04:00
|
|
|
: aFrame);
|
2013-03-16 09:40:15 +04:00
|
|
|
if (rangeFrame) {
|
|
|
|
return !rangeFrame->ShouldUseNativeStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 18:24:57 +03:00
|
|
|
if (aAppearance == StyleAppearance::SpinnerUpbutton ||
|
|
|
|
aAppearance == StyleAppearance::SpinnerDownbutton) {
|
2013-12-05 20:20:34 +04:00
|
|
|
nsNumberControlFrame* numberControlFrame =
|
|
|
|
nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
|
|
|
|
if (numberControlFrame) {
|
|
|
|
return !numberControlFrame->ShouldUseNativeStyleForSpinner();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 18:24:57 +03:00
|
|
|
return (aAppearance == StyleAppearance::NumberInput ||
|
|
|
|
aAppearance == StyleAppearance::Button ||
|
|
|
|
aAppearance == StyleAppearance::Textfield ||
|
2018-11-22 00:05:20 +03:00
|
|
|
aAppearance == StyleAppearance::Textarea ||
|
2018-10-24 18:24:57 +03:00
|
|
|
aAppearance == StyleAppearance::Listbox ||
|
|
|
|
aAppearance == StyleAppearance::Menulist ||
|
2020-02-19 17:48:43 +03:00
|
|
|
aAppearance == StyleAppearance::MenulistButton) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aFrame->GetContent()->IsHTMLElement() &&
|
2008-04-26 03:12:45 +04:00
|
|
|
aPresContext->HasAuthorSpecifiedRules(
|
2020-03-26 19:48:01 +03:00
|
|
|
aFrame, NS_AUTHOR_SPECIFIED_BORDER_OR_BACKGROUND);
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
2006-06-09 10:02:30 +04:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
bool nsNativeTheme::IsDisabled(nsIFrame* aFrame, EventStates aEventStates) {
|
2010-09-28 05:25:18 +04:00
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!content || !content->IsElement()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-28 05:25:18 +04:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsHTMLElement()) {
|
2010-10-20 15:26:32 +04:00
|
|
|
return aEventStates.HasState(NS_EVENT_STATE_DISABLED);
|
2010-09-28 05:25:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2017-12-07 21:13:50 +03:00
|
|
|
return content->AsElement()->AttrValueIs(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::disabled, u"true"_ns, eCaseMatters);
|
2010-09-28 05:25:18 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:13:48 +03:00
|
|
|
/* static */
|
|
|
|
bool nsNativeTheme::IsFrameRTL(nsIFrame* aFrame) {
|
2014-11-13 16:24:00 +03:00
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-28 21:22:05 +03:00
|
|
|
return aFrame->GetWritingMode().IsPhysicalRTL();
|
2008-11-28 01:14:54 +03:00
|
|
|
}
|
|
|
|
|
2020-02-10 22:26:01 +03:00
|
|
|
/* static */
|
2013-02-25 04:16:02 +04:00
|
|
|
bool nsNativeTheme::IsHTMLContent(nsIFrame* aFrame) {
|
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
return content && content->IsHTMLElement();
|
2013-02-25 04:16:02 +04:00
|
|
|
}
|
|
|
|
|
2008-01-13 07:13:50 +03:00
|
|
|
// scrollbar button:
|
|
|
|
int32_t nsNativeTheme::GetScrollbarButtonType(nsIFrame* aFrame) {
|
|
|
|
if (!aFrame) return 0;
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray strings[] = {
|
2018-04-03 06:21:06 +03:00
|
|
|
nsGkAtoms::scrollbarDownBottom, nsGkAtoms::scrollbarDownTop,
|
|
|
|
nsGkAtoms::scrollbarUpBottom, nsGkAtoms::scrollbarUpTop, nullptr};
|
2008-01-13 07:13:50 +03:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content || !content->IsElement()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (content->AsElement()->FindAttrValueIn(
|
2008-01-13 07:13:50 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-06-09 10:02:30 +04:00
|
|
|
// treeheadercell:
|
|
|
|
nsNativeTheme::TreeSortDirection nsNativeTheme::GetTreeSortDirection(
|
|
|
|
nsIFrame* aFrame) {
|
2010-10-11 02:07:00 +04:00
|
|
|
if (!aFrame || !aFrame->GetContent()) return eTreeSortDirection_Natural;
|
2006-06-09 10:02:30 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray strings[] = {nsGkAtoms::descending,
|
2018-04-03 06:21:06 +03:00
|
|
|
nsGkAtoms::ascending, nullptr};
|
2017-12-07 21:13:50 +03:00
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (content->IsElement()) {
|
|
|
|
switch (content->AsElement()->FindAttrValueIn(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::sortDirection, strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
return eTreeSortDirection_Descending;
|
|
|
|
case 1:
|
|
|
|
return eTreeSortDirection_Ascending;
|
|
|
|
}
|
2006-06-09 10:02:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return eTreeSortDirection_Natural;
|
|
|
|
}
|
|
|
|
|
2008-11-28 01:14:54 +03:00
|
|
|
bool nsNativeTheme::IsLastTreeHeaderCell(nsIFrame* aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2008-11-28 01:14:54 +03:00
|
|
|
|
|
|
|
// A tree column picker is always the last header cell.
|
2015-03-03 14:09:00 +03:00
|
|
|
if (aFrame->GetContent()->IsXULElement(nsGkAtoms::treecolpicker)) return true;
|
2008-11-28 01:14:54 +03:00
|
|
|
|
|
|
|
// Find the parent tree.
|
|
|
|
nsIContent* parent = aFrame->GetContent()->GetParent();
|
2015-03-03 14:09:00 +03:00
|
|
|
while (parent && !parent->IsXULElement(nsGkAtoms::tree)) {
|
2008-11-28 01:14:54 +03:00
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the column picker is visible, this can't be the last column.
|
2017-12-07 21:13:50 +03:00
|
|
|
if (parent && !parent->AsElement()->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::hidecolumnpicker,
|
|
|
|
u"true"_ns, eCaseMatters))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-28 01:14:54 +03:00
|
|
|
|
|
|
|
while ((aFrame = aFrame->GetNextSibling())) {
|
2018-01-10 19:14:16 +03:00
|
|
|
if (aFrame->GetRect().Width() > 0) return false;
|
2008-11-28 01:14:54 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-11-28 01:14:54 +03:00
|
|
|
}
|
|
|
|
|
2006-06-09 10:02:30 +04:00
|
|
|
// tab:
|
|
|
|
bool nsNativeTheme::IsBottomTab(nsIFrame* aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2006-06-09 10:02:30 +04:00
|
|
|
|
|
|
|
nsAutoString classStr;
|
2017-12-07 21:13:50 +03:00
|
|
|
if (aFrame->GetContent()->IsElement()) {
|
|
|
|
aFrame->GetContent()->AsElement()->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_class, classStr);
|
|
|
|
}
|
|
|
|
// FIXME: This looks bogus, shouldn't this be looking at GetClasses()?
|
2006-06-09 10:02:30 +04:00
|
|
|
return !classStr.IsEmpty() && classStr.Find("tab-bottom") != kNotFound;
|
|
|
|
}
|
|
|
|
|
2006-08-31 01:47:16 +04:00
|
|
|
bool nsNativeTheme::IsFirstTab(nsIFrame* aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2006-08-31 01:47:16 +04:00
|
|
|
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* first : aFrame->GetParent()->PrincipalChildList()) {
|
2018-01-10 19:14:16 +03:00
|
|
|
if (first->GetRect().Width() > 0 &&
|
2015-03-03 14:09:00 +03:00
|
|
|
first->GetContent()->IsXULElement(nsGkAtoms::tab))
|
2009-01-03 00:02:50 +03:00
|
|
|
return (first == aFrame);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-08-31 01:47:16 +04:00
|
|
|
}
|
|
|
|
|
2007-12-21 14:17:01 +03:00
|
|
|
bool nsNativeTheme::IsHorizontal(nsIFrame* aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2017-12-07 21:13:50 +03:00
|
|
|
|
|
|
|
if (!aFrame->GetContent()->IsElement()) return true;
|
|
|
|
|
|
|
|
return !aFrame->GetContent()->AsElement()->AttrValueIs(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::orient, nsGkAtoms::vertical, eCaseMatters);
|
2007-12-21 14:17:01 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool nsNativeTheme::IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2011-08-08 19:38:57 +04:00
|
|
|
|
|
|
|
if (aOffset == 0) return IsSelectedTab(aFrame);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t thisTabIndex = -1, selectedTabIndex = -1;
|
2011-08-08 19:38:57 +04:00
|
|
|
|
2016-01-29 17:42:14 +03:00
|
|
|
nsIFrame* currentTab = aFrame->GetParent()->PrincipalChildList().FirstChild();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; currentTab; currentTab = currentTab->GetNextSibling()) {
|
2018-01-10 19:14:16 +03:00
|
|
|
if (currentTab->GetRect().Width() == 0) continue;
|
2011-08-08 19:38:57 +04:00
|
|
|
if (aFrame == currentTab) thisTabIndex = i;
|
|
|
|
if (IsSelectedTab(currentTab)) selectedTabIndex = i;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thisTabIndex == -1 || selectedTabIndex == -1) return false;
|
|
|
|
|
|
|
|
return (thisTabIndex - selectedTabIndex == aOffset);
|
|
|
|
}
|
|
|
|
|
2011-03-01 05:06:22 +03:00
|
|
|
bool nsNativeTheme::IsIndeterminateProgress(nsIFrame* aFrame,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aEventStates) {
|
2018-11-20 17:12:33 +03:00
|
|
|
if (!aFrame || !aFrame->GetContent() ||
|
|
|
|
!aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-03-01 05:06:22 +03:00
|
|
|
}
|
|
|
|
|
2018-11-20 17:12:33 +03:00
|
|
|
return aEventStates.HasState(NS_EVENT_STATE_INDETERMINATE);
|
2006-06-09 10:02:30 +04:00
|
|
|
}
|
2009-01-12 22:23:51 +03:00
|
|
|
|
2011-05-17 20:39:22 +04:00
|
|
|
bool nsNativeTheme::IsVerticalProgress(nsIFrame* aFrame) {
|
2014-06-24 22:26:13 +04:00
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return IsVerticalMeter(aFrame);
|
2011-05-17 20:39:22 +04:00
|
|
|
}
|
|
|
|
|
2012-06-06 11:58:00 +04:00
|
|
|
bool nsNativeTheme::IsVerticalMeter(nsIFrame* aFrame) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aFrame, "You have to pass a non-null aFrame");
|
2014-06-24 22:26:13 +04:00
|
|
|
switch (aFrame->StyleDisplay()->mOrient) {
|
2016-10-28 07:17:20 +03:00
|
|
|
case StyleOrient::Horizontal:
|
2014-06-24 22:26:13 +04:00
|
|
|
return false;
|
2016-10-28 07:17:20 +03:00
|
|
|
case StyleOrient::Vertical:
|
2014-06-24 22:26:13 +04:00
|
|
|
return true;
|
2016-10-28 07:17:20 +03:00
|
|
|
case StyleOrient::Inline:
|
2014-06-24 22:26:13 +04:00
|
|
|
return aFrame->GetWritingMode().IsVertical();
|
2016-10-28 07:17:20 +03:00
|
|
|
case StyleOrient::Block:
|
2014-06-24 22:26:13 +04:00
|
|
|
return !aFrame->GetWritingMode().IsVertical();
|
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected -moz-orient value");
|
2014-06-24 22:26:13 +04:00
|
|
|
return false;
|
2012-06-06 11:58:00 +04:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:23:51 +03:00
|
|
|
// menupopup:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsNativeTheme::IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!aFrame) return false;
|
2009-01-12 22:23:51 +03:00
|
|
|
|
|
|
|
nsIContent* parentContent = aFrame->GetContent()->GetParent();
|
2015-03-03 14:09:00 +03:00
|
|
|
if (!parentContent || !parentContent->IsXULElement(nsGkAtoms::menu))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-12 22:23:51 +03:00
|
|
|
|
|
|
|
nsIFrame* parent = aFrame;
|
|
|
|
while ((parent = parent->GetParent())) {
|
|
|
|
if (parent->GetContent() == parentContent) {
|
|
|
|
if (aLeftOfParent) {
|
2015-11-10 08:37:32 +03:00
|
|
|
LayoutDeviceIntRect selfBounds, parentBounds;
|
2016-08-19 02:03:04 +03:00
|
|
|
selfBounds = aFrame->GetNearestWidget()->GetScreenBounds();
|
|
|
|
parentBounds = parent->GetNearestWidget()->GetScreenBounds();
|
2018-01-10 19:14:16 +03:00
|
|
|
*aLeftOfParent = selfBounds.X() < parentBounds.X();
|
2009-01-12 22:23:51 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-12 22:23:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-12 22:23:51 +03:00
|
|
|
}
|
2010-11-13 11:19:38 +03:00
|
|
|
|
2011-06-25 01:00:46 +04:00
|
|
|
bool nsNativeTheme::IsRegularMenuItem(nsIFrame* aFrame) {
|
2011-07-11 18:05:07 +04:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(aFrame);
|
2011-06-25 01:00:46 +04:00
|
|
|
return !(menuFrame &&
|
|
|
|
(menuFrame->IsOnMenuBar() || menuFrame->IsParentMenuList()));
|
|
|
|
}
|
|
|
|
|
2010-11-13 11:19:38 +03:00
|
|
|
bool nsNativeTheme::QueueAnimatedContentForRefresh(nsIContent* aContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aMinimumFrameRate) {
|
2010-11-13 11:19:38 +03:00
|
|
|
NS_ASSERTION(aContent, "Null pointer!");
|
|
|
|
NS_ASSERTION(aMinimumFrameRate, "aMinimumFrameRate must be non-zero!");
|
|
|
|
NS_ASSERTION(aMinimumFrameRate <= 1000,
|
|
|
|
"aMinimumFrameRate must be less than 1000!");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t timeout = 1000 / aMinimumFrameRate;
|
2013-01-15 16:22:03 +04:00
|
|
|
timeout = std::min(mAnimatedContentTimeout, timeout);
|
2010-11-13 11:19:38 +03:00
|
|
|
|
|
|
|
if (!mAnimatedContentTimer) {
|
2017-10-16 09:12:54 +03:00
|
|
|
mAnimatedContentTimer = NS_NewTimer();
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(mAnimatedContentTimer, false);
|
2010-11-13 11:19:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimatedContentList.IsEmpty() || timeout != mAnimatedContentTimeout) {
|
|
|
|
nsresult rv;
|
|
|
|
if (!mAnimatedContentList.IsEmpty()) {
|
|
|
|
rv = mAnimatedContentTimer->Cancel();
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2010-11-13 11:19:38 +03:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:46:47 +03:00
|
|
|
if (XRE_IsContentProcess() && NS_IsMainThread()) {
|
|
|
|
mAnimatedContentTimer->SetTarget(
|
|
|
|
aContent->OwnerDoc()->EventTargetFor(TaskCategory::Other));
|
|
|
|
}
|
2010-11-13 11:19:38 +03:00
|
|
|
rv = mAnimatedContentTimer->InitWithCallback(this, timeout,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2010-11-13 11:19:38 +03:00
|
|
|
|
|
|
|
mAnimatedContentTimeout = timeout;
|
|
|
|
}
|
|
|
|
|
2020-04-24 16:31:14 +03:00
|
|
|
// XXX(Bug 1631371) Check if this should use a fallible operation as it
|
|
|
|
// pretended earlier.
|
|
|
|
mAnimatedContentList.AppendElement(aContent);
|
2010-11-13 11:19:38 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-11-13 11:19:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeTheme::Notify(nsITimer* aTimer) {
|
|
|
|
NS_ASSERTION(aTimer == mAnimatedContentTimer, "Wrong timer!");
|
|
|
|
|
|
|
|
// XXX Assumes that calling nsIFrame::Invalidate won't reenter
|
|
|
|
// QueueAnimatedContentForRefresh.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mAnimatedContentList.Length();
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
2010-11-13 11:19:38 +03:00
|
|
|
nsIFrame* frame = mAnimatedContentList[index]->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2012-08-29 09:39:31 +04:00
|
|
|
frame->InvalidateFrame();
|
2010-11-13 11:19:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mAnimatedContentList.Clear();
|
2012-09-28 10:57:33 +04:00
|
|
|
mAnimatedContentTimeout = UINT32_MAX;
|
2010-11-13 11:19:38 +03:00
|
|
|
return NS_OK;
|
2017-07-26 21:18:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeTheme::GetName(nsACString& aName) {
|
|
|
|
aName.AssignLiteral("nsNativeTheme");
|
|
|
|
return NS_OK;
|
2010-11-13 11:19:38 +03:00
|
|
|
}
|
2011-08-08 18:42:45 +04:00
|
|
|
|
|
|
|
nsIFrame* nsNativeTheme::GetAdjacentSiblingFrameWithSameAppearance(
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIFrame* aFrame, bool aNextSibling) {
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!aFrame) return nullptr;
|
2011-08-08 18:42:45 +04:00
|
|
|
|
|
|
|
// Find the next visible sibling.
|
|
|
|
nsIFrame* sibling = aFrame;
|
|
|
|
do {
|
|
|
|
sibling =
|
|
|
|
aNextSibling ? sibling->GetNextSibling() : sibling->GetPrevSibling();
|
2018-01-10 19:14:16 +03:00
|
|
|
} while (sibling && sibling->GetRect().Width() == 0);
|
2011-08-08 18:42:45 +04:00
|
|
|
|
|
|
|
// Check same appearance and adjacency.
|
|
|
|
if (!sibling ||
|
2020-07-17 01:04:12 +03:00
|
|
|
sibling->StyleDisplay()->EffectiveAppearance() !=
|
|
|
|
aFrame->StyleDisplay()->EffectiveAppearance() ||
|
2018-01-10 19:14:16 +03:00
|
|
|
(sibling->GetRect().XMost() != aFrame->GetRect().X() &&
|
|
|
|
aFrame->GetRect().XMost() != sibling->GetRect().X()))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-08-08 18:42:45 +04:00
|
|
|
return sibling;
|
|
|
|
}
|
2013-03-16 09:40:15 +04:00
|
|
|
|
|
|
|
bool nsNativeTheme::IsRangeHorizontal(nsIFrame* aFrame) {
|
2013-03-29 00:25:05 +04:00
|
|
|
nsIFrame* rangeFrame = aFrame;
|
2017-04-30 18:30:08 +03:00
|
|
|
if (!rangeFrame->IsRangeFrame()) {
|
2013-11-06 14:05:18 +04:00
|
|
|
// If the thumb's frame is passed in, get its range parent:
|
2013-03-29 00:25:05 +04:00
|
|
|
rangeFrame = aFrame->GetParent();
|
|
|
|
}
|
2017-04-30 18:30:08 +03:00
|
|
|
if (rangeFrame->IsRangeFrame()) {
|
2013-11-06 14:05:18 +04:00
|
|
|
return static_cast<nsRangeFrame*>(rangeFrame)->IsHorizontal();
|
|
|
|
}
|
|
|
|
// Not actually a range frame - just use the ratio of the frame's size to
|
|
|
|
// decide:
|
|
|
|
return aFrame->GetSize().width >= aFrame->GetSize().height;
|
2013-03-16 09:40:15 +04:00
|
|
|
}
|
2013-05-19 19:01:28 +04:00
|
|
|
|
2013-05-31 06:23:49 +04:00
|
|
|
static nsIFrame* GetBodyFrame(nsIFrame* aCanvasFrame) {
|
|
|
|
nsIContent* content = aCanvasFrame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
nsIContent* body = content->OwnerDoc()->GetBodyElement();
|
2013-05-31 06:23:49 +04:00
|
|
|
if (!body) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return body->GetPrimaryFrame();
|
|
|
|
}
|
|
|
|
|
2019-10-24 00:00:28 +03:00
|
|
|
/* static */
|
2013-05-19 19:01:28 +04:00
|
|
|
bool nsNativeTheme::IsDarkBackground(nsIFrame* aFrame) {
|
2013-05-21 18:27:31 +04:00
|
|
|
nsIScrollableFrame* scrollFrame = nullptr;
|
2013-05-19 19:01:28 +04:00
|
|
|
while (!scrollFrame && aFrame) {
|
|
|
|
scrollFrame = aFrame->GetScrollTargetFrame();
|
2013-05-21 18:27:31 +04:00
|
|
|
aFrame = aFrame->GetParent();
|
2013-05-19 19:01:28 +04:00
|
|
|
}
|
2013-05-21 18:27:31 +04:00
|
|
|
if (!scrollFrame) return false;
|
|
|
|
|
2013-05-19 19:01:28 +04:00
|
|
|
nsIFrame* frame = scrollFrame->GetScrolledFrame();
|
2013-05-31 06:23:49 +04:00
|
|
|
if (nsCSSRendering::IsCanvasFrame(frame)) {
|
|
|
|
// For canvas frames, prefer to look at the body first, because the body
|
|
|
|
// background color is most likely what will be visible as the background
|
|
|
|
// color of the page, even if the html element has a different background
|
|
|
|
// color which prevents that of the body frame to propagate to the viewport.
|
|
|
|
nsIFrame* bodyFrame = GetBodyFrame(frame);
|
|
|
|
if (bodyFrame) {
|
|
|
|
frame = bodyFrame;
|
|
|
|
}
|
|
|
|
}
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* bgSC = nullptr;
|
2013-05-30 22:27:57 +04:00
|
|
|
if (!nsCSSRendering::FindBackground(frame, &bgSC) ||
|
2016-12-29 18:03:29 +03:00
|
|
|
bgSC->StyleBackground()->IsTransparent(bgSC)) {
|
2013-05-30 22:27:57 +04:00
|
|
|
nsIFrame* backgroundFrame =
|
|
|
|
nsCSSRendering::FindNonTransparentBackgroundFrame(frame, true);
|
|
|
|
nsCSSRendering::FindBackground(backgroundFrame, &bgSC);
|
|
|
|
}
|
|
|
|
if (bgSC) {
|
2016-12-29 18:03:29 +03:00
|
|
|
nscolor bgColor = bgSC->StyleBackground()->BackgroundColor(bgSC);
|
2013-05-19 19:01:28 +04:00
|
|
|
// Consider the background color dark if the sum of the r, g and b values is
|
2013-05-21 19:04:16 +04:00
|
|
|
// less than 384 in a semi-transparent document. This heuristic matches
|
2013-05-19 19:01:28 +04:00
|
|
|
// 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;
|
|
|
|
}
|
2018-06-21 09:32:17 +03:00
|
|
|
|
2018-10-24 18:24:57 +03:00
|
|
|
bool nsNativeTheme::IsWidgetScrollbarPart(StyleAppearance aAppearance) {
|
|
|
|
switch (aAppearance) {
|
2018-07-25 16:03:45 +03:00
|
|
|
case StyleAppearance::ScrollbarVertical:
|
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
case StyleAppearance::ScrollbarthumbVertical:
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
2020-03-11 17:44:20 +03:00
|
|
|
case StyleAppearance::ScrollbartrackHorizontal:
|
|
|
|
case StyleAppearance::ScrollbartrackVertical:
|
2018-07-25 16:03:45 +03:00
|
|
|
case StyleAppearance::Scrollcorner:
|
2018-06-21 09:32:17 +03:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|