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"
|
2005-08-20 11:13:18 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresShell.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"
|
2011-07-01 14:20:45 +04:00
|
|
|
#include "nsIDOMXULMenuListElement.h"
|
2005-08-20 11:13:18 +04:00
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsIComponentManager.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"
|
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"
|
2013-05-31 06:23:49 +04:00
|
|
|
#include "nsIDocumentInlines.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;
|
|
|
|
|
2005-08-20 11:13:18 +04:00
|
|
|
nsNativeTheme::nsNativeTheme()
|
2012-09-28 10:57:33 +04:00
|
|
|
: 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
|
|
|
|
2005-08-20 11:13:35 +04:00
|
|
|
nsIPresShell *
|
2005-08-20 11:14:11 +04:00
|
|
|
nsNativeTheme::GetPresShell(nsIFrame* aFrame)
|
2005-08-20 11:13:18 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2015-10-29 09:06:31 +03:00
|
|
|
nsPresContext* context = aFrame->PresContext();
|
2012-07-30 18:20:58 +04:00
|
|
|
return context ? context->GetPresShell() : nullptr;
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2012-08-22 19:56:38 +04:00
|
|
|
nsNativeTheme::GetContentState(nsIFrame* aFrame, uint8_t aWidgetType)
|
2005-08-20 11:13:18 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2014-04-03 08:18:36 +04:00
|
|
|
return EventStates();
|
2005-08-20 11:13:18 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isXULCheckboxRadio =
|
2007-05-09 23:17:17 +04:00
|
|
|
(aWidgetType == NS_THEME_CHECKBOX ||
|
2008-11-03 16:12:59 +03:00
|
|
|
aWidgetType == NS_THEME_RADIO) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aFrame->GetContent()->IsXULElement();
|
2005-08-20 11:13:56 +04:00
|
|
|
if (isXULCheckboxRadio)
|
2005-08-20 11:13:33 +04:00
|
|
|
aFrame = aFrame->GetParent();
|
2005-08-20 11:13:20 +04:00
|
|
|
|
2009-04-14 21:22:04 +04:00
|
|
|
if (!aFrame->GetContent())
|
2014-04-03 08:18:36 +04:00
|
|
|
return EventStates();
|
2009-04-14 21:22:04 +04:00
|
|
|
|
2005-08-20 11:14:11 +04:00
|
|
|
nsIPresShell *shell = GetPresShell(aFrame);
|
2005-08-20 11:13:18 +04:00
|
|
|
if (!shell)
|
2014-04-03 08:18:36 +04:00
|
|
|
return EventStates();
|
2005-08-20 11:13:18 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
// <input type=number> needs special handling since its nested native
|
|
|
|
// anonymous <input type=text> takes focus for it.
|
2013-12-09 03:23:28 +04:00
|
|
|
if (aWidgetType == NS_THEME_NUMBER_INPUT &&
|
2015-03-03 14:08:59 +03:00
|
|
|
frameContent->IsHTMLElement(nsGkAtoms::input)) {
|
2013-12-05 20:20:34 +04:00
|
|
|
nsNumberControlFrame *numberControlFrame = do_QueryFrame(aFrame);
|
|
|
|
if (numberControlFrame && numberControlFrame->IsFocused()) {
|
|
|
|
flags |= NS_EVENT_STATE_FOCUS;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
2005-08-20 11:13:20 +04:00
|
|
|
|
2008-11-03 16:12:59 +03:00
|
|
|
if (isXULCheckboxRadio && aWidgetType == NS_THEME_RADIO) {
|
2005-08-20 11:13:20 +04:00
|
|
|
if (IsFocused(aFrame))
|
|
|
|
flags |= NS_EVENT_STATE_FOCUS;
|
|
|
|
}
|
2010-04-21 18:53:42 +04:00
|
|
|
|
|
|
|
// 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.
|
2013-12-09 03:23:28 +04:00
|
|
|
if (aWidgetType == NS_THEME_NUMBER_INPUT ||
|
|
|
|
aWidgetType == NS_THEME_TEXTFIELD ||
|
2010-04-21 18:53:42 +04:00
|
|
|
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)
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* doc = aFrame->GetContent()->OwnerDoc();
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = doc->GetWindow();
|
2011-10-18 15:19:44 +04:00
|
|
|
if (window && !window->ShouldShowFocusRing())
|
|
|
|
flags &= ~NS_EVENT_STATE_FOCUS;
|
2010-04-21 18:53:42 +04:00
|
|
|
#endif
|
2005-08-20 11:13:20 +04:00
|
|
|
|
2005-08-20 11:13:18 +04:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2013-02-25 04:26:07 +04:00
|
|
|
/* static */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
nsNativeTheme::CheckBooleanAttr(nsIFrame* aFrame, nsAtom* aAtom)
|
2005-08-20 11:13:18 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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())
|
2011-10-17 18:59:28 +04:00
|
|
|
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,
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
eCaseMatters);
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 04:26:07 +04:00
|
|
|
/* static */
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2017-10-03 01:05:19 +03:00
|
|
|
nsNativeTheme::CheckIntAttr(nsIFrame* aFrame, nsAtom* aAtom, int32_t defaultValue)
|
2005-08-20 11:13:18 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2008-03-27 08:36:20 +03:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
// When we are using the HTML progress element,
|
|
|
|
// we can get the value from the IDL property.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aFrame && aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
|
2013-08-02 02:24:22 +04:00
|
|
|
return static_cast<HTMLProgressElement*>(aFrame->GetContent())->Value();
|
2013-02-25 04:26:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aFrame && aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
|
2013-08-02 02:24:22 +04:00
|
|
|
return static_cast<HTMLProgressElement*>(aFrame->GetContent())->Max();
|
2013-02-25 04:26:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (double)std::max(nsNativeTheme::CheckIntAttr(aFrame, nsGkAtoms::max, 100), 1);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsNativeTheme::GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected)
|
2005-08-20 11:13:18 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-08-11 01:23:50 +04:00
|
|
|
nsNativeTheme::IsButtonTypeMenu(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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,
|
|
|
|
NS_LITERAL_STRING("menu"),
|
|
|
|
eCaseMatters);
|
2009-08-11 01:23:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-08-08 18:42:45 +04:00
|
|
|
nsNativeTheme::IsPressedButton(nsIFrame* aFrame)
|
|
|
|
{
|
2016-05-18 20:29:56 +03:00
|
|
|
EventStates eventState = GetContentState(aFrame, NS_THEME_TOOLBARBUTTON);
|
2011-08-08 18:42:45 +04:00
|
|
|
if (IsDisabled(aFrame, eventState))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-08-08 18:42:45 +04:00
|
|
|
|
|
|
|
return IsOpenButton(aFrame) ||
|
|
|
|
eventState.HasAllStates(NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-01-30 10:19:41 +03:00
|
|
|
nsNativeTheme::GetIndeterminate(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-08-20 11:14:04 +04:00
|
|
|
nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aWidgetType)
|
2005-08-20 11:13:18 +04:00
|
|
|
{
|
|
|
|
// Check for specific widgets to see if HTML has overridden the style.
|
2010-06-21 16:37:35 +04:00
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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.
|
|
|
|
if (aWidgetType == NS_THEME_RESIZER) {
|
|
|
|
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) {
|
|
|
|
return IsWidgetStyled(aPresContext, parentFrame,
|
2017-05-21 12:15:00 +03:00
|
|
|
parentFrame->StyleDisplay()->mAppearance);
|
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.
|
|
|
|
*/
|
2016-05-18 20:29:56 +03:00
|
|
|
if (aWidgetType == NS_THEME_PROGRESSCHUNK ||
|
2011-05-06 14:00:30 +04:00
|
|
|
aWidgetType == NS_THEME_PROGRESSBAR) {
|
2016-05-18 20:29:56 +03:00
|
|
|
nsProgressFrame* progressFrame = do_QueryFrame(aWidgetType == NS_THEME_PROGRESSCHUNK
|
2011-05-06 14:00:30 +04:00
|
|
|
? aFrame->GetParent() : aFrame);
|
|
|
|
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.
|
|
|
|
*/
|
2016-05-18 20:29:56 +03:00
|
|
|
if (aWidgetType == NS_THEME_METERCHUNK ||
|
2012-05-16 20:31:01 +04:00
|
|
|
aWidgetType == NS_THEME_METERBAR) {
|
2016-05-18 20:29:56 +03:00
|
|
|
nsMeterFrame* meterFrame = do_QueryFrame(aWidgetType == NS_THEME_METERCHUNK
|
2012-05-16 20:31:01 +04:00
|
|
|
? aFrame->GetParent() : aFrame);
|
|
|
|
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.
|
|
|
|
*/
|
2013-03-29 00:25:05 +04:00
|
|
|
if (aWidgetType == NS_THEME_RANGE ||
|
|
|
|
aWidgetType == NS_THEME_RANGE_THUMB) {
|
|
|
|
nsRangeFrame* rangeFrame =
|
|
|
|
do_QueryFrame(aWidgetType == NS_THEME_RANGE_THUMB
|
|
|
|
? aFrame->GetParent() : aFrame);
|
2013-03-16 09:40:15 +04:00
|
|
|
if (rangeFrame) {
|
|
|
|
return !rangeFrame->ShouldUseNativeStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 20:29:56 +03:00
|
|
|
if (aWidgetType == NS_THEME_SPINNER_UPBUTTON ||
|
|
|
|
aWidgetType == NS_THEME_SPINNER_DOWNBUTTON) {
|
2013-12-05 20:20:34 +04:00
|
|
|
nsNumberControlFrame* numberControlFrame =
|
|
|
|
nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
|
|
|
|
if (numberControlFrame) {
|
|
|
|
return !numberControlFrame->ShouldUseNativeStyleForSpinner();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-09 03:23:28 +04:00
|
|
|
return (aWidgetType == NS_THEME_NUMBER_INPUT ||
|
|
|
|
aWidgetType == NS_THEME_BUTTON ||
|
2007-10-09 03:11:01 +04:00
|
|
|
aWidgetType == NS_THEME_TEXTFIELD ||
|
|
|
|
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
|
|
|
|
aWidgetType == NS_THEME_LISTBOX ||
|
2016-05-18 20:29:56 +03:00
|
|
|
aWidgetType == NS_THEME_MENULIST) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aFrame->GetContent()->IsHTMLElement() &&
|
2008-04-26 03:12:45 +04:00
|
|
|
aPresContext->HasAuthorSpecifiedRules(aFrame,
|
|
|
|
NS_AUTHOR_SPECIFIED_BORDER |
|
2009-04-01 05:07:18 +04:00
|
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND);
|
2005-08-20 11:13:18 +04:00
|
|
|
}
|
2006-06-09 10:02:30 +04:00
|
|
|
|
2010-09-28 05:25:18 +04:00
|
|
|
bool
|
2014-04-03 08:18:36 +04:00
|
|
|
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,
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
eCaseMatters);
|
2010-09-28 05:25:18 +04:00
|
|
|
}
|
|
|
|
|
2016-10-20 07:57:55 +03:00
|
|
|
/* static */ bool
|
2008-11-28 01:14:54 +03:00
|
|
|
nsNativeTheme::IsFrameRTL(nsIFrame* aFrame)
|
|
|
|
{
|
2014-11-13 16:24:00 +03:00
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
WritingMode wm = aFrame->GetWritingMode();
|
|
|
|
return !(wm.IsVertical() ? wm.IsVerticalLR() : wm.IsBidiLTR());
|
2008-11-28 01:14:54 +03:00
|
|
|
}
|
|
|
|
|
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:
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2008-01-13 07:13:50 +03:00
|
|
|
nsNativeTheme::GetScrollbarButtonType(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return 0;
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray strings[] =
|
2018-04-11 11:22:05 +03:00
|
|
|
{&nsGkAtoms::scrollbarDownBottom, &nsGkAtoms::scrollbarDownTop,
|
|
|
|
&nsGkAtoms::scrollbarUpBottom, &nsGkAtoms::scrollbarUpTop,
|
2012-07-30 18:20:58 +04:00
|
|
|
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(kNameSpaceID_None,
|
2011-10-14 22:11:22 +04:00
|
|
|
nsGkAtoms::sbattr,
|
2008-01-13 07:13:50 +03:00
|
|
|
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())
|
2006-06-09 10:02:30 +04:00
|
|
|
return eTreeSortDirection_Natural;
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray strings[] =
|
2018-04-11 11:22:05 +03:00
|
|
|
{&nsGkAtoms::descending, &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;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-11-28 01:14:54 +03:00
|
|
|
nsNativeTheme::IsLastTreeHeaderCell(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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))
|
2011-10-17 18:59:28 +04:00
|
|
|
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,
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
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)
|
2011-10-17 18:59:28 +04:00
|
|
|
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:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-06-09 10:02:30 +04:00
|
|
|
nsNativeTheme::IsBottomTab(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-08-31 01:47:16 +04:00
|
|
|
nsNativeTheme::IsFirstTab(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-12-21 14:17:01 +03:00
|
|
|
nsNativeTheme::IsHorizontal(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsNativeTheme::IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset)
|
2011-08-08 19:38:57 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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)
|
2011-08-08 19:38:57 +04:00
|
|
|
continue;
|
|
|
|
if (aFrame == currentTab)
|
|
|
|
thisTabIndex = i;
|
|
|
|
if (IsSelectedTab(currentTab))
|
|
|
|
selectedTabIndex = i;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thisTabIndex == -1 || selectedTabIndex == -1)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-08-08 19:38:57 +04:00
|
|
|
|
|
|
|
return (thisTabIndex - selectedTabIndex == aOffset);
|
|
|
|
}
|
|
|
|
|
2006-06-09 10:02:30 +04:00
|
|
|
// progressbar:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-03-01 05:06:22 +03:00
|
|
|
nsNativeTheme::IsIndeterminateProgress(nsIFrame* aFrame,
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates aEventStates)
|
2006-06-09 10:02:30 +04:00
|
|
|
{
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!aFrame || !aFrame->GetContent()|| !aFrame->GetContent()->IsElement())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-06-09 10:02:30 +04:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aFrame->GetContent()->IsHTMLElement(nsGkAtoms::progress)) {
|
2011-03-01 05:06:22 +03:00
|
|
|
return aEventStates.HasState(NS_EVENT_STATE_INDETERMINATE);
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
return aFrame->GetContent()->AsElement()->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::mode,
|
|
|
|
NS_LITERAL_STRING("undetermined"),
|
|
|
|
eCaseMatters);
|
2006-06-09 10:02:30 +04:00
|
|
|
}
|
2009-01-12 22:23:51 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-17 20:39:22 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("unexpected -moz-orient value");
|
|
|
|
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)
|
2009-01-12 22:23:51 +03:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
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-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-06-25 01:00:46 +04:00
|
|
|
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->GetParentMenuListType() != eNotMenuList));
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-07-01 14:20:45 +04:00
|
|
|
nsNativeTheme::IsMenuListEditable(nsIFrame *aFrame)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEditable = false;
|
2011-07-01 14:20:45 +04:00
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menulist = do_QueryInterface(aFrame->GetContent());
|
|
|
|
if (menulist)
|
|
|
|
menulist->GetEditable(&isEditable);
|
|
|
|
return isEditable;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-11-13 11:19:38 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAnimatedContentList.AppendElement(aContent)) {
|
|
|
|
NS_WARNING("Out of memory!");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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(nsIFrame* aFrame,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aNextSibling)
|
2011-08-08 18:42:45 +04:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2012-07-30 18:20:58 +04:00
|
|
|
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 ||
|
2017-05-21 12:15:00 +03:00
|
|
|
sibling->StyleDisplay()->mAppearance != aFrame->StyleDisplay()->mAppearance ||
|
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;
|
|
|
|
}
|
|
|
|
nsIDocument* document = content->OwnerDoc();
|
|
|
|
nsIContent* body = document->GetBodyElement();
|
|
|
|
if (!body) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return body->GetPrimaryFrame();
|
|
|
|
}
|
|
|
|
|
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 what
|
2013-05-19 19:01:28 +04:00
|
|
|
// 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;
|
|
|
|
}
|