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"
|
2021-10-01 14:48:17 +03:00
|
|
|
#include "nsLayoutUtils.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"
|
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
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
/* static */ ElementState nsNativeTheme::GetContentState(
|
2020-10-27 18:16:49 +03:00
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
2021-10-07 09:55:36 +03:00
|
|
|
if (!aFrame) {
|
2022-06-08 02:09:52 +03:00
|
|
|
return ElementState();
|
2021-10-07 09:55:36 +03:00
|
|
|
}
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2021-12-09 04:11:58 +03:00
|
|
|
nsIContent* frameContent = aFrame->GetContent();
|
|
|
|
if (!frameContent || !frameContent->IsElement()) {
|
2022-06-08 02:09:52 +03:00
|
|
|
return ElementState();
|
2021-03-17 00:53:20 +03:00
|
|
|
}
|
2009-04-14 21:22:04 +04:00
|
|
|
|
2021-12-09 04:11:58 +03:00
|
|
|
const bool isXULElement = frameContent->IsXULElement();
|
|
|
|
if (isXULElement) {
|
|
|
|
if (aAppearance == StyleAppearance::CheckboxLabel ||
|
|
|
|
aAppearance == StyleAppearance::RadioLabel) {
|
|
|
|
aFrame = aFrame->GetParent()->GetParent();
|
|
|
|
frameContent = aFrame->GetContent();
|
|
|
|
} else if (aAppearance == StyleAppearance::Checkbox ||
|
|
|
|
aAppearance == StyleAppearance::Radio ||
|
|
|
|
aAppearance == StyleAppearance::ToolbarbuttonDropdown ||
|
|
|
|
aAppearance == StyleAppearance::Treeheadersortarrow ||
|
|
|
|
aAppearance == StyleAppearance::ButtonArrowPrevious ||
|
|
|
|
aAppearance == StyleAppearance::ButtonArrowNext ||
|
|
|
|
aAppearance == StyleAppearance::ButtonArrowUp ||
|
|
|
|
aAppearance == StyleAppearance::ButtonArrowDown) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
frameContent = aFrame->GetContent();
|
2013-12-11 06:13:06 +04:00
|
|
|
}
|
2021-12-09 04:11:58 +03:00
|
|
|
MOZ_ASSERT(frameContent && frameContent->IsElement());
|
|
|
|
}
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
ElementState flags = frameContent->AsElement()->StyleState();
|
2021-12-09 04:11:58 +03:00
|
|
|
nsNumberControlFrame* numberControlFrame =
|
|
|
|
nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
|
|
|
|
if (numberControlFrame &&
|
2022-03-09 14:45:10 +03:00
|
|
|
numberControlFrame->GetContent()->AsElement()->StyleState().HasState(
|
2022-06-08 02:09:52 +03:00
|
|
|
ElementState::DISABLED)) {
|
|
|
|
flags |= ElementState::DISABLED;
|
2021-12-09 04:11:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isXULElement) {
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckBooleanAttr(aFrame, nsGkAtoms::disabled)) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::DISABLED;
|
2011-06-01 05:46:56 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-12-09 04:11:58 +03:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::RadioLabel:
|
|
|
|
case StyleAppearance::Radio: {
|
|
|
|
if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::FOCUS;
|
2021-10-07 09:55:36 +03:00
|
|
|
nsPIDOMWindowOuter* window =
|
|
|
|
aFrame->GetContent()->OwnerDoc()->GetWindow();
|
|
|
|
if (window && window->ShouldShowFocusRing()) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::FOCUSRING;
|
2021-10-07 09:55:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CheckBooleanAttr(aFrame, nsGkAtoms::selected)) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::CHECKED;
|
2021-10-07 09:55:36 +03:00
|
|
|
}
|
2021-12-09 04:11:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StyleAppearance::CheckboxLabel:
|
|
|
|
case StyleAppearance::Checkbox: {
|
|
|
|
if (CheckBooleanAttr(aFrame, nsGkAtoms::checked)) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::CHECKED;
|
2021-12-09 04:11:58 +03:00
|
|
|
} else if (CheckBooleanAttr(aFrame, nsGkAtoms::indeterminate)) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::INDETERMINATE;
|
2021-12-09 04:11:58 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case StyleAppearance::MenulistButton:
|
|
|
|
case StyleAppearance::Menulist:
|
|
|
|
case StyleAppearance::NumberInput:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::Searchfield:
|
|
|
|
case StyleAppearance::Textarea: {
|
|
|
|
if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) {
|
2022-06-08 02:09:52 +03:00
|
|
|
flags |= ElementState::FOCUS | ElementState::FOCUSRING;
|
2021-12-09 04:11:58 +03:00
|
|
|
}
|
|
|
|
break;
|
2020-05-16 21:03:54 +03:00
|
|
|
}
|
2021-12-09 04:11:58 +03:00
|
|
|
default:
|
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2022-06-08 02:09:54 +03:00
|
|
|
ElementState state = GetContentState(aFrame, StyleAppearance::Toolbarbutton);
|
|
|
|
if (state.HasState(ElementState::DISABLED)) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-08 18:42:45 +04:00
|
|
|
|
|
|
|
return IsOpenButton(aFrame) ||
|
2022-06-08 02:09:54 +03:00
|
|
|
state.HasAllStates(ElementState::ACTIVE | ElementState::HOVER);
|
2011-08-08 18:42:45 +04: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.
|
2021-02-20 03:15:42 +03: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.
|
2021-02-20 03:15:42 +03:00
|
|
|
//
|
|
|
|
// note that the condition below looks a bit suspect but it's the right
|
|
|
|
// one. If there's no valid appearance, then we should return true, it's
|
|
|
|
// effectively the same as if it had overridden the appearance.
|
2010-06-21 16:37:35 +04:00
|
|
|
parentFrame = parentFrame->GetParent();
|
2021-02-20 03:15:42 +03:00
|
|
|
if (!parentFrame) {
|
|
|
|
return false;
|
2010-06-21 16:37:35 +04:00
|
|
|
}
|
2021-02-20 03:15:42 +03:00
|
|
|
auto parentAppearance =
|
|
|
|
parentFrame->StyleDisplay()->EffectiveAppearance();
|
|
|
|
return parentAppearance == StyleAppearance::None ||
|
|
|
|
IsWidgetStyled(aPresContext, parentFrame, parentAppearance);
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 16:19:32 +03:00
|
|
|
return nsLayoutUtils::AuthorSpecifiedBorderBackgroundDisablesTheming(
|
|
|
|
aAppearance) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aFrame->GetContent()->IsHTMLElement() &&
|
2021-10-01 14:48:17 +03:00
|
|
|
aFrame->Style()->HasAuthorSpecifiedBorderOrBackground();
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
2006-06-09 10:02:30 +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
|
|
|
}
|
|
|
|
|
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()?
|
Bug 1772006 - Part 5: Simplify and move the string searching APIs from ns[T]StringObsolete, r=xpcom-reviewers,necko-reviewers,eeejay,dragana,barret
The biggest set of APIs from ns[T]StringObsolete which are still heavily used
are the string searching APIs. It appears the intention was for these to be
replaced by the `FindInReadable` APIs, however that doesn't appear to have
happened.
In addition, the APIs have some quirks around their handling of mixed character
widths. These APIs generally supported both narrow strings and the native
string type, probably because char16_t string literals weren't available until
c++11. Finally they also used easy-to-confuse unlabeled boolean and integer
optional arguments to control behaviour.
These patches do the following major changes to the searching APIs:
1. The ASCII case-insensitive search method was split out as
LowerCaseFindASCII, rather than using a boolean. This should be less
error-prone and more explicit, and allows the method to continue to use
narrow string literals for all string types (as only ASCII is supported).
2. The other [R]Find methods were restricted to only support arguments with
matching character types. I considered adding a FindASCII method which would
use narrow string literals for both wide and narrow strings but it would've
been the same amount of work as changing all of the literals to unicode
literals.
This ends up being the bulk of the changes in the patch.
3. All find methods were re-implemented using std::basic_string_view's find
algorithm or stl algorithms to reduce code complexity, and avoid the need to
carry around the logic from nsStringObsolete.cpp.
4. The implementations were moved to nsTStringRepr.cpp.
5. An overload of Find was added to try to catch callers which previously
called `Find(..., false)` or `Find(..., true)` to set case-sensitivity, due
to booleans normally implicitly coercing to `index_type`. This should
probably be removed at some point, but may be useful during the transition.
Differential Revision: https://phabricator.services.mozilla.com/D148300
2022-07-30 03:12:48 +03:00
|
|
|
return !classStr.IsEmpty() && classStr.Find(u"tab-bottom") != kNotFound;
|
2006-06-09 10:02:30 +04:00
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
|
|
|
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
|
|
|
|
2021-05-11 16:57:18 +03:00
|
|
|
/* static */
|
|
|
|
bool nsNativeTheme::IsDarkBackground(nsIFrame* aFrame) {
|
|
|
|
// Try to find the scrolled frame. Note that for stuff like xul <tree> there
|
|
|
|
// might be none.
|
|
|
|
{
|
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
nsIScrollableFrame* scrollFrame = nullptr;
|
|
|
|
while (!scrollFrame && frame) {
|
|
|
|
scrollFrame = frame->GetScrollTargetFrame();
|
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
|
|
|
if (scrollFrame) {
|
|
|
|
aFrame = scrollFrame->GetScrolledFrame();
|
|
|
|
} else {
|
|
|
|
// Leave aFrame untouched.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 12:51:47 +03:00
|
|
|
auto color =
|
|
|
|
nsCSSRendering::FindEffectiveBackgroundColor(
|
|
|
|
aFrame, /* aStopAtThemed = */ false, /* aPreferBodyToCanvas = */ true)
|
|
|
|
.mColor;
|
2022-04-01 04:21:22 +03:00
|
|
|
return LookAndFeel::IsDarkColor(color);
|
2013-05-19 19:01:28 +04:00
|
|
|
}
|
2018-06-21 09:32:17 +03:00
|
|
|
|
2021-01-21 00:33:34 +03:00
|
|
|
/*static*/
|
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;
|
|
|
|
}
|
|
|
|
}
|