2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Ryner <bryner@brianryner.com> (Original Author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsNativeTheme.h"
|
2009-04-01 14:59:02 -07:00
|
|
|
#include "nsIWidget.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStateManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2010-04-21 07:53:42 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2011-05-06 03:00:30 -07:00
|
|
|
#include "nsProgressFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsNativeTheme::nsNativeTheme()
|
2010-11-13 00:19:38 -08:00
|
|
|
: mAnimatedContentTimeout(PR_UINT32_MAX)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-13 00:19:38 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(nsNativeTheme, nsITimerCallback)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPresShell *
|
|
|
|
nsNativeTheme::GetPresShell(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// this is a workaround for the egcs 1.1.2 not inliningg
|
|
|
|
// aFrame->GetPresContext(), which causes an undefined symbol
|
|
|
|
nsPresContext *context = aFrame->GetStyleContext()->GetRuleNode()->GetPresContext();
|
|
|
|
return context ? context->GetPresShell() : nsnull;
|
|
|
|
}
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNativeTheme::GetContentState(nsIFrame* aFrame, PRUint8 aWidgetType)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
2010-10-20 04:26:32 -07:00
|
|
|
return nsEventStates();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool isXULCheckboxRadio =
|
2007-05-09 12:17:17 -07:00
|
|
|
(aWidgetType == NS_THEME_CHECKBOX ||
|
2008-11-03 05:12:59 -08:00
|
|
|
aWidgetType == NS_THEME_RADIO) &&
|
2009-08-24 13:02:07 -07:00
|
|
|
aFrame->GetContent()->IsXUL();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isXULCheckboxRadio)
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
2009-04-14 10:22:04 -07:00
|
|
|
if (!aFrame->GetContent())
|
2010-10-20 04:26:32 -07:00
|
|
|
return nsEventStates();
|
2009-04-14 10:22:04 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPresShell *shell = GetPresShell(aFrame);
|
|
|
|
if (!shell)
|
2010-10-20 04:26:32 -07:00
|
|
|
return nsEventStates();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager* esm = shell->GetPresContext()->EventStateManager();
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates flags = esm->GetContentState(aFrame->GetContent(), PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-03 05:12:59 -08:00
|
|
|
if (isXULCheckboxRadio && aWidgetType == NS_THEME_RADIO) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (IsFocused(aFrame))
|
|
|
|
flags |= NS_EVENT_STATE_FOCUS;
|
|
|
|
}
|
2010-04-21 07:53:42 -07: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.
|
|
|
|
if (aWidgetType == NS_THEME_TEXTFIELD ||
|
|
|
|
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
|
|
|
|
aWidgetType == NS_THEME_SEARCHFIELD ||
|
|
|
|
aWidgetType == NS_THEME_LISTBOX) {
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
// On Windows, focused buttons are always drawn as such by the native theme.
|
|
|
|
if (aWidgetType == NS_THEME_BUTTON)
|
|
|
|
return flags;
|
|
|
|
#endif
|
|
|
|
#if defined(XP_MACOSX) || defined(XP_WIN)
|
|
|
|
nsIDocument* doc = aFrame->GetContent()->GetOwnerDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsPIDOMWindow* window = doc->GetWindow();
|
|
|
|
if (window && !window->ShouldShowFocusRing())
|
|
|
|
flags &= ~NS_EVENT_STATE_FOCUS;
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2009-04-14 10:22:04 -07:00
|
|
|
if (!content)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-08-24 13:02:07 -07:00
|
|
|
if (content->IsHTML())
|
2007-03-22 10:30:00 -07:00
|
|
|
return content->HasAttr(kNameSpaceID_None, aAtom);
|
|
|
|
|
|
|
|
// For XML/XUL elements, an attribute must be equal to the literal
|
|
|
|
// string "true" to be counted as true. An empty string should _not_
|
|
|
|
// be counted as true.
|
|
|
|
return content->AttrValueIs(kNameSpaceID_None, aAtom,
|
|
|
|
NS_LITERAL_STRING("true"), eCaseMatters);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2008-03-26 22:36:20 -07:00
|
|
|
nsNativeTheme::CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, PRInt32 defaultValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
2008-03-26 22:36:20 -07:00
|
|
|
return defaultValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString attr;
|
|
|
|
aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attr);
|
|
|
|
PRInt32 err, value = attr.ToInteger(&err);
|
2008-03-26 22:36:20 -07:00
|
|
|
if (attr.IsEmpty() || NS_FAILED(err))
|
|
|
|
return defaultValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
2009-08-24 13:02:07 -07:00
|
|
|
if (content->IsXUL()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// For a XUL checkbox or radio button, the state of the parent determines
|
|
|
|
// the checked state
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
} else {
|
|
|
|
// Check for an HTML input element
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(content);
|
|
|
|
if (inputElt) {
|
|
|
|
PRBool checked;
|
|
|
|
inputElt->GetChecked(&checked);
|
|
|
|
return checked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CheckBooleanAttr(aFrame, aCheckSelected ? nsWidgetAtoms::selected
|
|
|
|
: nsWidgetAtoms::checked);
|
|
|
|
}
|
|
|
|
|
2009-08-10 14:23:50 -07:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsButtonTypeMenu(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
return content->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::type,
|
|
|
|
NS_LITERAL_STRING("menu"), eCaseMatters);
|
|
|
|
}
|
|
|
|
|
2009-01-29 23:19:41 -08:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::GetIndeterminate(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
2009-08-24 13:02:07 -07:00
|
|
|
if (content->IsXUL()) {
|
2009-01-29 23:19:41 -08:00
|
|
|
// For a XUL checkbox or radio button, the state of the parent determines
|
|
|
|
// the state
|
|
|
|
return CheckBooleanAttr(aFrame->GetParent(), nsWidgetAtoms::indeterminate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for an HTML input element
|
2010-08-04 19:40:18 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(content);
|
2009-01-29 23:19:41 -08:00
|
|
|
if (inputElt) {
|
|
|
|
PRBool indeterminate;
|
|
|
|
inputElt->GetIndeterminate(&indeterminate);
|
|
|
|
return indeterminate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
|
|
|
|
PRUint8 aWidgetType)
|
|
|
|
{
|
|
|
|
// Check for specific widgets to see if HTML has overridden the style.
|
2010-06-21 05:37:35 -07:00
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// Resizers have some special handling, dependent on whether in a scrollable
|
|
|
|
// container or not. If so, use the scrollable container's to determine
|
|
|
|
// whether the style is overriden instead of the resizer. This allows a
|
|
|
|
// non-native transparent resizer to be used instead. Otherwise, we just
|
|
|
|
// fall through and return false.
|
|
|
|
if (aWidgetType == NS_THEME_RESIZER) {
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
|
|
|
if (parentFrame && parentFrame->GetType() == nsWidgetAtoms::scrollFrame) {
|
|
|
|
// if the parent is a scrollframe, the resizer should be native themed
|
|
|
|
// only if the scrollable area doesn't override the widget style.
|
|
|
|
parentFrame = parentFrame->GetParent();
|
|
|
|
if (parentFrame) {
|
|
|
|
return IsWidgetStyled(aPresContext, parentFrame,
|
|
|
|
parentFrame->GetStyleDisplay()->mAppearance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 03:00:30 -07: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.
|
|
|
|
*/
|
|
|
|
if (aWidgetType == NS_THEME_PROGRESSBAR_CHUNK ||
|
|
|
|
aWidgetType == NS_THEME_PROGRESSBAR) {
|
|
|
|
nsProgressFrame* progressFrame = do_QueryFrame(aWidgetType == NS_THEME_PROGRESSBAR_CHUNK
|
|
|
|
? aFrame->GetParent() : aFrame);
|
|
|
|
if (progressFrame) {
|
|
|
|
return !progressFrame->ShouldUseNativeStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 05:37:35 -07:00
|
|
|
return (aWidgetType == NS_THEME_BUTTON ||
|
2007-10-08 16:11:01 -07:00
|
|
|
aWidgetType == NS_THEME_TEXTFIELD ||
|
|
|
|
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
|
|
|
|
aWidgetType == NS_THEME_LISTBOX ||
|
|
|
|
aWidgetType == NS_THEME_DROPDOWN) &&
|
2009-08-24 13:02:07 -07:00
|
|
|
aFrame->GetContent()->IsHTML() &&
|
2008-04-25 16:12:45 -07:00
|
|
|
aPresContext->HasAuthorSpecifiedRules(aFrame,
|
|
|
|
NS_AUTHOR_SPECIFIED_BORDER |
|
2009-03-31 18:07:18 -07:00
|
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-27 18:25:18 -07:00
|
|
|
bool
|
2010-10-20 04:26:32 -07:00
|
|
|
nsNativeTheme::IsDisabled(nsIFrame* aFrame, nsEventStates aEventStates)
|
2010-09-27 18:25:18 -07:00
|
|
|
{
|
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content->IsHTML()) {
|
2010-10-20 04:26:32 -07:00
|
|
|
return aEventStates.HasState(NS_EVENT_STATE_DISABLED);
|
2010-09-27 18:25:18 -07: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.
|
|
|
|
return content->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
|
|
|
|
NS_LITERAL_STRING("true"), eCaseMatters);
|
|
|
|
}
|
|
|
|
|
2008-11-27 14:14:54 -08:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsFrameRTL(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return aFrame && aFrame->GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
|
|
|
|
}
|
|
|
|
|
2008-01-12 20:13:50 -08:00
|
|
|
// scrollbar button:
|
|
|
|
PRInt32
|
|
|
|
nsNativeTheme::GetScrollbarButtonType(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsWidgetAtoms::scrollbarDownBottom, &nsWidgetAtoms::scrollbarDownTop,
|
|
|
|
&nsWidgetAtoms::scrollbarUpBottom, &nsWidgetAtoms::scrollbarUpTop,
|
|
|
|
nsnull};
|
|
|
|
|
|
|
|
switch (aFrame->GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsWidgetAtoms::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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// treeheadercell:
|
|
|
|
nsNativeTheme::TreeSortDirection
|
|
|
|
nsNativeTheme::GetTreeSortDirection(nsIFrame* aFrame)
|
|
|
|
{
|
2010-10-10 15:07:00 -07:00
|
|
|
if (!aFrame || !aFrame->GetContent())
|
2007-03-22 10:30:00 -07:00
|
|
|
return eTreeSortDirection_Natural;
|
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsWidgetAtoms::descending, &nsWidgetAtoms::ascending, nsnull};
|
|
|
|
switch (aFrame->GetContent()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsWidgetAtoms::sortdirection,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: return eTreeSortDirection_Descending;
|
|
|
|
case 1: return eTreeSortDirection_Ascending;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eTreeSortDirection_Natural;
|
|
|
|
}
|
|
|
|
|
2008-11-27 14:14:54 -08:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsLastTreeHeaderCell(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// A tree column picker is always the last header cell.
|
|
|
|
if (aFrame->GetContent()->Tag() == nsWidgetAtoms::treecolpicker)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// Find the parent tree.
|
|
|
|
nsIContent* parent = aFrame->GetContent()->GetParent();
|
|
|
|
while (parent && parent->Tag() != nsWidgetAtoms::tree) {
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the column picker is visible, this can't be the last column.
|
|
|
|
if (parent && !parent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidecolumnpicker,
|
|
|
|
NS_LITERAL_STRING("true"), eCaseMatters))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
while ((aFrame = aFrame->GetNextSibling())) {
|
|
|
|
if (aFrame->GetRect().width > 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// tab:
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsBottomTab(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsAutoString classStr;
|
|
|
|
aFrame->GetContent()->GetAttr(kNameSpaceID_None, nsWidgetAtoms::_class, classStr);
|
|
|
|
return !classStr.IsEmpty() && classStr.Find("tab-bottom") != kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsFirstTab(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-01-02 13:02:50 -08:00
|
|
|
nsIFrame* first = aFrame->GetParent()->GetFirstChild(nsnull);
|
|
|
|
while (first) {
|
|
|
|
if (first->GetRect().width > 0 && first->GetContent()->Tag() == nsWidgetAtoms::tab)
|
|
|
|
return (first == aFrame);
|
|
|
|
first = first->GetNextSibling();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsLastTab(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-01-02 13:02:50 -08:00
|
|
|
while ((aFrame = aFrame->GetNextSibling())) {
|
|
|
|
if (aFrame->GetRect().width > 0 && aFrame->GetContent()->Tag() == nsWidgetAtoms::tab)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-21 03:17:01 -08:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsHorizontal(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return !aFrame->GetContent()->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::orient,
|
|
|
|
nsWidgetAtoms::vertical,
|
|
|
|
eCaseMatters);
|
|
|
|
}
|
|
|
|
|
2008-11-27 14:16:13 -08:00
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsNextToSelectedTab(nsIFrame* aFrame, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aOffset == 0)
|
|
|
|
return IsSelectedTab(aFrame);
|
|
|
|
|
|
|
|
PRInt32 thisTabIndex = -1, selectedTabIndex = -1;
|
|
|
|
|
|
|
|
nsIFrame* currentTab = aFrame->GetParent()->GetFirstChild(NULL);
|
|
|
|
for (PRInt32 i = 0; currentTab; currentTab = currentTab->GetNextSibling()) {
|
|
|
|
if (currentTab->GetRect().width == 0)
|
|
|
|
continue;
|
|
|
|
if (aFrame == currentTab)
|
|
|
|
thisTabIndex = i;
|
|
|
|
if (IsSelectedTab(currentTab))
|
|
|
|
selectedTabIndex = i;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thisTabIndex == -1 || selectedTabIndex == -1)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return (thisTabIndex - selectedTabIndex == aOffset);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// progressbar:
|
|
|
|
PRBool
|
2011-02-28 18:06:22 -08:00
|
|
|
nsNativeTheme::IsIndeterminateProgress(nsIFrame* aFrame,
|
|
|
|
nsEventStates aEventStates)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2011-02-28 18:06:22 -08:00
|
|
|
if (aFrame->GetContent()->IsHTML(nsWidgetAtoms::progress)) {
|
|
|
|
return aEventStates.HasState(NS_EVENT_STATE_INDETERMINATE);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return aFrame->GetContent()->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::mode,
|
|
|
|
NS_LITERAL_STRING("undetermined"),
|
|
|
|
eCaseMatters);
|
|
|
|
}
|
2009-01-12 11:23:51 -08:00
|
|
|
|
|
|
|
// menupopup:
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::IsSubmenu(nsIFrame* aFrame, PRBool* aLeftOfParent)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIContent* parentContent = aFrame->GetContent()->GetParent();
|
|
|
|
if (!parentContent || parentContent->Tag() != nsWidgetAtoms::menu)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* parent = aFrame;
|
|
|
|
while ((parent = parent->GetParent())) {
|
|
|
|
if (parent->GetContent() == parentContent) {
|
|
|
|
if (aLeftOfParent) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect selfBounds, parentBounds;
|
2010-07-02 12:11:04 -07:00
|
|
|
aFrame->GetNearestWidget()->GetScreenBounds(selfBounds);
|
|
|
|
parent->GetNearestWidget()->GetScreenBounds(parentBounds);
|
2009-01-12 11:23:51 -08:00
|
|
|
*aLeftOfParent = selfBounds.x < parentBounds.x;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-11-13 00:19:38 -08:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNativeTheme::QueueAnimatedContentForRefresh(nsIContent* aContent,
|
|
|
|
PRUint32 aMinimumFrameRate)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "Null pointer!");
|
|
|
|
NS_ASSERTION(aMinimumFrameRate, "aMinimumFrameRate must be non-zero!");
|
|
|
|
NS_ASSERTION(aMinimumFrameRate <= 1000,
|
|
|
|
"aMinimumFrameRate must be less than 1000!");
|
|
|
|
|
|
|
|
PRUint32 timeout = PRUint32(NS_floor(1000 / aMinimumFrameRate));
|
|
|
|
timeout = PR_MIN(mAnimatedContentTimeout, timeout);
|
|
|
|
|
|
|
|
if (!mAnimatedContentTimer) {
|
|
|
|
mAnimatedContentTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(mAnimatedContentTimer, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimatedContentList.IsEmpty() || timeout != mAnimatedContentTimeout) {
|
|
|
|
nsresult rv;
|
|
|
|
if (!mAnimatedContentList.IsEmpty()) {
|
|
|
|
rv = mAnimatedContentTimer->Cancel();
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mAnimatedContentTimer->InitWithCallback(this, timeout,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
|
|
|
mAnimatedContentTimeout = timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAnimatedContentList.AppendElement(aContent)) {
|
|
|
|
NS_WARNING("Out of memory!");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeTheme::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aTimer == mAnimatedContentTimer, "Wrong timer!");
|
|
|
|
|
|
|
|
// XXX Assumes that calling nsIFrame::Invalidate won't reenter
|
|
|
|
// QueueAnimatedContentForRefresh.
|
|
|
|
|
|
|
|
PRUint32 count = mAnimatedContentList.Length();
|
|
|
|
for (PRUint32 index = 0; index < count; index++) {
|
|
|
|
nsIFrame* frame = mAnimatedContentList[index]->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
#ifdef MOZ_ENABLE_LIBXUL
|
|
|
|
frame->InvalidateOverflowRect();
|
|
|
|
#else
|
|
|
|
frame->InvalidateOverflowRectExternal();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mAnimatedContentList.Clear();
|
|
|
|
mAnimatedContentTimeout = PR_UINT32_MAX;
|
|
|
|
return NS_OK;
|
|
|
|
}
|