mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 07:05:24 +00:00
e96ed2b16c
--HG-- rename : layout/xul/base/src/crashtests/131008-1.xul => layout/xul/crashtests/131008-1.xul rename : layout/xul/base/src/crashtests/137216-1.xul => layout/xul/crashtests/137216-1.xul rename : layout/xul/base/src/crashtests/140218-1.xml => layout/xul/crashtests/140218-1.xml rename : layout/xul/base/src/crashtests/151826-1.xul => layout/xul/crashtests/151826-1.xul rename : layout/xul/base/src/crashtests/168724-1.xul => layout/xul/crashtests/168724-1.xul rename : layout/xul/base/src/crashtests/189814-1.xul => layout/xul/crashtests/189814-1.xul rename : layout/xul/base/src/crashtests/237787-1.xul => layout/xul/crashtests/237787-1.xul rename : layout/xul/base/src/crashtests/265161-1.xul => layout/xul/crashtests/265161-1.xul rename : layout/xul/base/src/crashtests/289410-1.xul => layout/xul/crashtests/289410-1.xul rename : layout/xul/base/src/crashtests/291702-1.xul => layout/xul/crashtests/291702-1.xul rename : layout/xul/base/src/crashtests/291702-2.xul => layout/xul/crashtests/291702-2.xul rename : layout/xul/base/src/crashtests/291702-3.xul => layout/xul/crashtests/291702-3.xul rename : layout/xul/base/src/crashtests/294371-1.xul => layout/xul/crashtests/294371-1.xul rename : layout/xul/base/src/crashtests/311457-1.html => layout/xul/crashtests/311457-1.html rename : layout/xul/base/src/crashtests/321056-1.xhtml => layout/xul/crashtests/321056-1.xhtml rename : layout/xul/base/src/crashtests/322786-1.xul => layout/xul/crashtests/322786-1.xul rename : layout/xul/base/src/crashtests/325377.xul => layout/xul/crashtests/325377.xul rename : layout/xul/base/src/crashtests/326834-1-inner.xul => layout/xul/crashtests/326834-1-inner.xul rename : layout/xul/base/src/crashtests/326834-1.html => layout/xul/crashtests/326834-1.html rename : layout/xul/base/src/crashtests/326879-1.xul => layout/xul/crashtests/326879-1.xul rename : layout/xul/base/src/crashtests/327776-1.xul => layout/xul/crashtests/327776-1.xul rename : layout/xul/base/src/crashtests/328135-1.xul => layout/xul/crashtests/328135-1.xul rename : layout/xul/base/src/crashtests/329327-1.xul => layout/xul/crashtests/329327-1.xul rename : layout/xul/base/src/crashtests/329407-1.xml => layout/xul/crashtests/329407-1.xml rename : layout/xul/base/src/crashtests/329477-1.xhtml => layout/xul/crashtests/329477-1.xhtml rename : layout/xul/base/src/crashtests/336962-1.xul => layout/xul/crashtests/336962-1.xul rename : layout/xul/base/src/crashtests/344228-1.xul => layout/xul/crashtests/344228-1.xul rename : layout/xul/base/src/crashtests/346083-1.xul => layout/xul/crashtests/346083-1.xul rename : layout/xul/base/src/crashtests/346281-1.xul => layout/xul/crashtests/346281-1.xul rename : layout/xul/base/src/crashtests/350460.xul => layout/xul/crashtests/350460.xul rename : layout/xul/base/src/crashtests/360642-1.xul => layout/xul/crashtests/360642-1.xul rename : layout/xul/base/src/crashtests/365151.xul => layout/xul/crashtests/365151.xul rename : layout/xul/base/src/crashtests/366112-1.xul => layout/xul/crashtests/366112-1.xul rename : layout/xul/base/src/crashtests/369942-1.xhtml => layout/xul/crashtests/369942-1.xhtml rename : layout/xul/base/src/crashtests/374102-1.xul => layout/xul/crashtests/374102-1.xul rename : layout/xul/base/src/crashtests/376137-1.html => layout/xul/crashtests/376137-1.html rename : layout/xul/base/src/crashtests/376137-2.html => layout/xul/crashtests/376137-2.html rename : layout/xul/base/src/crashtests/377592-1.svg => layout/xul/crashtests/377592-1.svg rename : layout/xul/base/src/crashtests/381862.html => layout/xul/crashtests/381862.html rename : layout/xul/base/src/crashtests/382746-1.xul => layout/xul/crashtests/382746-1.xul rename : layout/xul/base/src/crashtests/382899-1.xul => layout/xul/crashtests/382899-1.xul rename : layout/xul/base/src/crashtests/383236-1.xul => layout/xul/crashtests/383236-1.xul rename : layout/xul/base/src/crashtests/384037-1.xhtml => layout/xul/crashtests/384037-1.xhtml rename : layout/xul/base/src/crashtests/384105-1-inner.xul => layout/xul/crashtests/384105-1-inner.xul rename : layout/xul/base/src/crashtests/384105-1.html => layout/xul/crashtests/384105-1.html rename : layout/xul/base/src/crashtests/384491-1.xhtml => layout/xul/crashtests/384491-1.xhtml rename : layout/xul/base/src/crashtests/384871-1-inner.xul => layout/xul/crashtests/384871-1-inner.xul rename : layout/xul/base/src/crashtests/384871-1.html => layout/xul/crashtests/384871-1.html rename : layout/xul/base/src/crashtests/387033-1.xhtml => layout/xul/crashtests/387033-1.xhtml rename : layout/xul/base/src/crashtests/387080-1.xul => layout/xul/crashtests/387080-1.xul rename : layout/xul/base/src/crashtests/391974-1-inner.xul => layout/xul/crashtests/391974-1-inner.xul rename : layout/xul/base/src/crashtests/391974-1.html => layout/xul/crashtests/391974-1.html rename : layout/xul/base/src/crashtests/394120-1.xhtml => layout/xul/crashtests/394120-1.xhtml rename : layout/xul/base/src/crashtests/397293.xhtml => layout/xul/crashtests/397293.xhtml rename : layout/xul/base/src/crashtests/397304-1.html => layout/xul/crashtests/397304-1.html rename : layout/xul/base/src/crashtests/398326-1.xhtml => layout/xul/crashtests/398326-1.xhtml rename : layout/xul/base/src/crashtests/399013.xul => layout/xul/crashtests/399013.xul rename : layout/xul/base/src/crashtests/400779-1.xhtml => layout/xul/crashtests/400779-1.xhtml rename : layout/xul/base/src/crashtests/402912-1.xhtml => layout/xul/crashtests/402912-1.xhtml rename : layout/xul/base/src/crashtests/408904-1.xul => layout/xul/crashtests/408904-1.xul rename : layout/xul/base/src/crashtests/412479-1.xhtml => layout/xul/crashtests/412479-1.xhtml rename : layout/xul/base/src/crashtests/415394-1.xhtml => layout/xul/crashtests/415394-1.xhtml rename : layout/xul/base/src/crashtests/420424-1.xul => layout/xul/crashtests/420424-1.xul rename : layout/xul/base/src/crashtests/430356-1.xhtml => layout/xul/crashtests/430356-1.xhtml rename : layout/xul/base/src/crashtests/431738.xhtml => layout/xul/crashtests/431738.xhtml rename : layout/xul/base/src/crashtests/432058-1.xul => layout/xul/crashtests/432058-1.xul rename : layout/xul/base/src/crashtests/432068-1.xul => layout/xul/crashtests/432068-1.xul rename : layout/xul/base/src/crashtests/432068-2.xul => layout/xul/crashtests/432068-2.xul rename : layout/xul/base/src/crashtests/433296-1.xul => layout/xul/crashtests/433296-1.xul rename : layout/xul/base/src/crashtests/433429.xul => layout/xul/crashtests/433429.xul rename : layout/xul/base/src/crashtests/434458-1.xul => layout/xul/crashtests/434458-1.xul rename : layout/xul/base/src/crashtests/452185.html => layout/xul/crashtests/452185.html rename : layout/xul/base/src/crashtests/452185.xml => layout/xul/crashtests/452185.xml rename : layout/xul/base/src/crashtests/460900-1.xul => layout/xul/crashtests/460900-1.xul rename : layout/xul/base/src/crashtests/464149-1.xul => layout/xul/crashtests/464149-1.xul rename : layout/xul/base/src/crashtests/464407-1.xhtml => layout/xul/crashtests/464407-1.xhtml rename : layout/xul/base/src/crashtests/467080.xul => layout/xul/crashtests/467080.xul rename : layout/xul/base/src/crashtests/467481-1.xul => layout/xul/crashtests/467481-1.xul rename : layout/xul/base/src/crashtests/470063-1.html => layout/xul/crashtests/470063-1.html rename : layout/xul/base/src/crashtests/470272.html => layout/xul/crashtests/470272.html rename : layout/xul/base/src/crashtests/472189.xul => layout/xul/crashtests/472189.xul rename : layout/xul/base/src/crashtests/475133.html => layout/xul/crashtests/475133.html rename : layout/xul/base/src/crashtests/488210-1.xhtml => layout/xul/crashtests/488210-1.xhtml rename : layout/xul/base/src/crashtests/495728-1.xul => layout/xul/crashtests/495728-1.xul rename : layout/xul/base/src/crashtests/508927-1.xul => layout/xul/crashtests/508927-1.xul rename : layout/xul/base/src/crashtests/508927-2.xul => layout/xul/crashtests/508927-2.xul rename : layout/xul/base/src/crashtests/514300-1.xul => layout/xul/crashtests/514300-1.xul rename : layout/xul/base/src/crashtests/536931-1.xhtml => layout/xul/crashtests/536931-1.xhtml rename : layout/xul/base/src/crashtests/538308-1.xul => layout/xul/crashtests/538308-1.xul rename : layout/xul/base/src/crashtests/557174-1.xml => layout/xul/crashtests/557174-1.xml rename : layout/xul/base/src/crashtests/564705-1.xul => layout/xul/crashtests/564705-1.xul rename : layout/xul/base/src/crashtests/583957-1.html => layout/xul/crashtests/583957-1.html rename : layout/xul/base/src/crashtests/crashtests.list => layout/xul/crashtests/crashtests.list rename : layout/xul/base/src/crashtests/menulist-focused.xhtml => layout/xul/crashtests/menulist-focused.xhtml rename : layout/xul/base/src/moz.build => layout/xul/moz.build rename : layout/xul/base/src/nsBox.cpp => layout/xul/nsBox.cpp rename : layout/xul/base/src/nsBox.h => layout/xul/nsBox.h rename : layout/xul/base/src/nsBoxFrame.cpp => layout/xul/nsBoxFrame.cpp rename : layout/xul/base/src/nsBoxFrame.h => layout/xul/nsBoxFrame.h rename : layout/xul/base/src/nsBoxLayout.cpp => layout/xul/nsBoxLayout.cpp rename : layout/xul/base/src/nsBoxLayout.h => layout/xul/nsBoxLayout.h rename : layout/xul/base/src/nsBoxLayoutState.cpp => layout/xul/nsBoxLayoutState.cpp rename : layout/xul/base/src/nsBoxLayoutState.h => layout/xul/nsBoxLayoutState.h rename : layout/xul/base/src/nsBoxObject.cpp => layout/xul/nsBoxObject.cpp rename : layout/xul/base/src/nsBoxObject.h => layout/xul/nsBoxObject.h rename : layout/xul/base/src/nsButtonBoxFrame.cpp => layout/xul/nsButtonBoxFrame.cpp rename : layout/xul/base/src/nsButtonBoxFrame.h => layout/xul/nsButtonBoxFrame.h rename : layout/xul/base/src/nsContainerBoxObject.cpp => layout/xul/nsContainerBoxObject.cpp rename : layout/xul/base/src/nsDeckFrame.cpp => layout/xul/nsDeckFrame.cpp rename : layout/xul/base/src/nsDeckFrame.h => layout/xul/nsDeckFrame.h rename : layout/xul/base/src/nsDocElementBoxFrame.cpp => layout/xul/nsDocElementBoxFrame.cpp rename : layout/xul/base/src/nsGroupBoxFrame.cpp => layout/xul/nsGroupBoxFrame.cpp rename : layout/xul/base/public/nsIBoxObject.idl => layout/xul/nsIBoxObject.idl rename : layout/xul/base/public/nsIBrowserBoxObject.idl => layout/xul/nsIBrowserBoxObject.idl rename : layout/xul/base/public/nsIContainerBoxObject.idl => layout/xul/nsIContainerBoxObject.idl rename : layout/xul/base/public/nsIEditorBoxObject.idl => layout/xul/nsIEditorBoxObject.idl rename : layout/xul/base/public/nsIIFrameBoxObject.idl => layout/xul/nsIIFrameBoxObject.idl rename : layout/xul/base/public/nsIListBoxObject.idl => layout/xul/nsIListBoxObject.idl rename : layout/xul/base/public/nsIMenuBoxObject.idl => layout/xul/nsIMenuBoxObject.idl rename : layout/xul/base/public/nsIPopupBoxObject.idl => layout/xul/nsIPopupBoxObject.idl rename : layout/xul/base/src/nsIRootBox.h => layout/xul/nsIRootBox.h rename : layout/xul/base/public/nsIScrollBoxObject.idl => layout/xul/nsIScrollBoxObject.idl rename : layout/xul/base/public/nsIScrollbarMediator.h => layout/xul/nsIScrollbarMediator.h rename : layout/xul/base/public/nsISliderListener.idl => layout/xul/nsISliderListener.idl rename : layout/xul/base/src/nsImageBoxFrame.cpp => layout/xul/nsImageBoxFrame.cpp rename : layout/xul/base/src/nsImageBoxFrame.h => layout/xul/nsImageBoxFrame.h rename : layout/xul/base/src/nsLeafBoxFrame.cpp => layout/xul/nsLeafBoxFrame.cpp rename : layout/xul/base/src/nsLeafBoxFrame.h => layout/xul/nsLeafBoxFrame.h rename : layout/xul/base/src/nsListBoxBodyFrame.cpp => layout/xul/nsListBoxBodyFrame.cpp rename : layout/xul/base/src/nsListBoxBodyFrame.h => layout/xul/nsListBoxBodyFrame.h rename : layout/xul/base/src/nsListBoxLayout.cpp => layout/xul/nsListBoxLayout.cpp rename : layout/xul/base/src/nsListBoxLayout.h => layout/xul/nsListBoxLayout.h rename : layout/xul/base/src/nsListBoxObject.cpp => layout/xul/nsListBoxObject.cpp rename : layout/xul/base/src/nsListItemFrame.cpp => layout/xul/nsListItemFrame.cpp rename : layout/xul/base/src/nsListItemFrame.h => layout/xul/nsListItemFrame.h rename : layout/xul/base/src/nsMenuBarFrame.cpp => layout/xul/nsMenuBarFrame.cpp rename : layout/xul/base/src/nsMenuBarFrame.h => layout/xul/nsMenuBarFrame.h rename : layout/xul/base/src/nsMenuBarListener.cpp => layout/xul/nsMenuBarListener.cpp rename : layout/xul/base/src/nsMenuBarListener.h => layout/xul/nsMenuBarListener.h rename : layout/xul/base/src/nsMenuBoxObject.cpp => layout/xul/nsMenuBoxObject.cpp rename : layout/xul/base/src/nsMenuFrame.cpp => layout/xul/nsMenuFrame.cpp rename : layout/xul/base/src/nsMenuFrame.h => layout/xul/nsMenuFrame.h rename : layout/xul/base/src/nsMenuParent.h => layout/xul/nsMenuParent.h rename : layout/xul/base/src/nsMenuPopupFrame.cpp => layout/xul/nsMenuPopupFrame.cpp rename : layout/xul/base/src/nsMenuPopupFrame.h => layout/xul/nsMenuPopupFrame.h rename : layout/xul/base/public/nsPIBoxObject.h => layout/xul/nsPIBoxObject.h rename : layout/xul/base/src/nsPIListBoxObject.h => layout/xul/nsPIListBoxObject.h rename : layout/xul/base/src/nsPopupBoxObject.cpp => layout/xul/nsPopupBoxObject.cpp rename : layout/xul/base/src/nsPopupSetFrame.cpp => layout/xul/nsPopupSetFrame.cpp rename : layout/xul/base/src/nsPopupSetFrame.h => layout/xul/nsPopupSetFrame.h rename : layout/xul/base/src/nsProgressMeterFrame.cpp => layout/xul/nsProgressMeterFrame.cpp rename : layout/xul/base/src/nsProgressMeterFrame.h => layout/xul/nsProgressMeterFrame.h rename : layout/xul/base/src/nsRepeatService.cpp => layout/xul/nsRepeatService.cpp rename : layout/xul/base/src/nsRepeatService.h => layout/xul/nsRepeatService.h rename : layout/xul/base/src/nsResizerFrame.cpp => layout/xul/nsResizerFrame.cpp rename : layout/xul/base/src/nsResizerFrame.h => layout/xul/nsResizerFrame.h rename : layout/xul/base/src/nsRootBoxFrame.cpp => layout/xul/nsRootBoxFrame.cpp rename : layout/xul/base/src/nsScrollBoxFrame.cpp => layout/xul/nsScrollBoxFrame.cpp rename : layout/xul/base/src/nsScrollBoxObject.cpp => layout/xul/nsScrollBoxObject.cpp rename : layout/xul/base/src/nsScrollbarButtonFrame.cpp => layout/xul/nsScrollbarButtonFrame.cpp rename : layout/xul/base/src/nsScrollbarButtonFrame.h => layout/xul/nsScrollbarButtonFrame.h rename : layout/xul/base/src/nsScrollbarFrame.cpp => layout/xul/nsScrollbarFrame.cpp rename : layout/xul/base/src/nsScrollbarFrame.h => layout/xul/nsScrollbarFrame.h rename : layout/xul/base/src/nsSliderFrame.cpp => layout/xul/nsSliderFrame.cpp rename : layout/xul/base/src/nsSliderFrame.h => layout/xul/nsSliderFrame.h rename : layout/xul/base/src/nsSplitterFrame.cpp => layout/xul/nsSplitterFrame.cpp rename : layout/xul/base/src/nsSplitterFrame.h => layout/xul/nsSplitterFrame.h rename : layout/xul/base/src/nsSprocketLayout.cpp => layout/xul/nsSprocketLayout.cpp rename : layout/xul/base/src/nsSprocketLayout.h => layout/xul/nsSprocketLayout.h rename : layout/xul/base/src/nsStackFrame.cpp => layout/xul/nsStackFrame.cpp rename : layout/xul/base/src/nsStackFrame.h => layout/xul/nsStackFrame.h rename : layout/xul/base/src/nsStackLayout.cpp => layout/xul/nsStackLayout.cpp rename : layout/xul/base/src/nsStackLayout.h => layout/xul/nsStackLayout.h rename : layout/xul/base/src/nsTextBoxFrame.cpp => layout/xul/nsTextBoxFrame.cpp rename : layout/xul/base/src/nsTextBoxFrame.h => layout/xul/nsTextBoxFrame.h rename : layout/xul/base/src/nsTitleBarFrame.cpp => layout/xul/nsTitleBarFrame.cpp rename : layout/xul/base/src/nsTitleBarFrame.h => layout/xul/nsTitleBarFrame.h rename : layout/xul/base/src/nsXULLabelFrame.cpp => layout/xul/nsXULLabelFrame.cpp rename : layout/xul/base/src/nsXULLabelFrame.h => layout/xul/nsXULLabelFrame.h rename : layout/xul/base/src/nsXULPopupManager.cpp => layout/xul/nsXULPopupManager.cpp rename : layout/xul/base/public/nsXULPopupManager.h => layout/xul/nsXULPopupManager.h rename : layout/xul/base/src/nsXULTooltipListener.cpp => layout/xul/nsXULTooltipListener.cpp rename : layout/xul/base/src/nsXULTooltipListener.h => layout/xul/nsXULTooltipListener.h rename : layout/xul/base/reftest/image-scaling-min-height-1-ref.xul => layout/xul/reftest/image-scaling-min-height-1-ref.xul rename : layout/xul/base/reftest/image-scaling-min-height-1.xul => layout/xul/reftest/image-scaling-min-height-1.xul rename : layout/xul/base/reftest/image-size-ref.xul => layout/xul/reftest/image-size-ref.xul rename : layout/xul/base/reftest/image-size.xul => layout/xul/reftest/image-size.xul rename : layout/xul/base/reftest/image4x3.png => layout/xul/reftest/image4x3.png rename : layout/xul/base/reftest/popup-explicit-size-ref.xul => layout/xul/reftest/popup-explicit-size-ref.xul rename : layout/xul/base/reftest/popup-explicit-size.xul => layout/xul/reftest/popup-explicit-size.xul rename : layout/xul/base/reftest/reftest.list => layout/xul/reftest/reftest.list rename : layout/xul/base/reftest/textbox-multiline-noresize.xul => layout/xul/reftest/textbox-multiline-noresize.xul rename : layout/xul/base/reftest/textbox-multiline-ref.xul => layout/xul/reftest/textbox-multiline-ref.xul rename : layout/xul/base/reftest/textbox-multiline-resize.xul => layout/xul/reftest/textbox-multiline-resize.xul rename : layout/xul/base/test/test_bug381167.xhtml => layout/xul/test/test_bug381167.xhtml rename : layout/xul/base/test/test_bug393970.xul => layout/xul/test/test_bug393970.xul rename : layout/xul/base/test/test_bug477754.xul => layout/xul/test/test_bug477754.xul rename : layout/xul/base/test/test_bug511075.html => layout/xul/test/test_bug511075.html rename : layout/xul/base/test/test_popupSizeTo.xul => layout/xul/test/test_popupSizeTo.xul rename : layout/xul/base/test/test_resizer.xul => layout/xul/test/test_resizer.xul rename : layout/xul/base/test/test_resizer_incontent.xul => layout/xul/test/test_resizer_incontent.xul rename : layout/xul/base/test/test_splitter.xul => layout/xul/test/test_splitter.xul rename : layout/xul/base/test/test_stack.xul => layout/xul/test/test_stack.xul rename : layout/xul/base/test/test_windowminmaxsize.xul => layout/xul/test/test_windowminmaxsize.xul rename : layout/xul/base/test/window_resizer.xul => layout/xul/test/window_resizer.xul rename : layout/xul/base/test/window_resizer_element.xul => layout/xul/test/window_resizer_element.xul
1158 lines
32 KiB
C++
1158 lines
32 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/. */
|
|
|
|
//
|
|
// Eric Vaughan
|
|
// Netscape Communications
|
|
//
|
|
// See documentation in associated header file
|
|
//
|
|
|
|
#include "nsSliderFrame.h"
|
|
#include "nsStyleContext.h"
|
|
#include "nsPresContext.h"
|
|
#include "nsIContent.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsINameSpaceManager.h"
|
|
#include "nsGkAtoms.h"
|
|
#include "nsHTMLParts.h"
|
|
#include "nsIPresShell.h"
|
|
#include "nsCSSRendering.h"
|
|
#include "nsEventListenerManager.h"
|
|
#include "nsIDOMMouseEvent.h"
|
|
#include "nsScrollbarButtonFrame.h"
|
|
#include "nsISliderListener.h"
|
|
#include "nsIScrollbarMediator.h"
|
|
#include "nsScrollbarFrame.h"
|
|
#include "nsRepeatService.h"
|
|
#include "nsBoxLayoutState.h"
|
|
#include "nsSprocketLayout.h"
|
|
#include "nsIServiceManager.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsLayoutUtils.h"
|
|
#include "nsDisplayList.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/LookAndFeel.h"
|
|
#include "mozilla/MouseEvents.h"
|
|
#include <algorithm>
|
|
|
|
using namespace mozilla;
|
|
|
|
bool nsSliderFrame::gMiddlePref = false;
|
|
int32_t nsSliderFrame::gSnapMultiplier;
|
|
|
|
// Turn this on if you want to debug slider frames.
|
|
#undef DEBUG_SLIDER
|
|
|
|
static already_AddRefed<nsIContent>
|
|
GetContentOfBox(nsIFrame *aBox)
|
|
{
|
|
nsCOMPtr<nsIContent> content = aBox->GetContent();
|
|
return content.forget();
|
|
}
|
|
|
|
nsIFrame*
|
|
NS_NewSliderFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
{
|
|
return new (aPresShell) nsSliderFrame(aPresShell, aContext);
|
|
}
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSliderFrame)
|
|
|
|
nsSliderFrame::nsSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext):
|
|
nsBoxFrame(aPresShell, aContext),
|
|
mCurPos(0),
|
|
mChange(0),
|
|
mUserChanged(false)
|
|
{
|
|
}
|
|
|
|
// stop timer
|
|
nsSliderFrame::~nsSliderFrame()
|
|
{
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::Init(nsIContent* aContent,
|
|
nsIFrame* aParent,
|
|
nsIFrame* aPrevInFlow)
|
|
{
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
static bool gotPrefs = false;
|
|
if (!gotPrefs) {
|
|
gotPrefs = true;
|
|
|
|
gMiddlePref = Preferences::GetBool("middlemouse.scrollbarPosition");
|
|
gSnapMultiplier = Preferences::GetInt("slider.snapMultiplier");
|
|
}
|
|
|
|
mCurPos = GetCurrentPosition(aContent);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::RemoveFrame(ChildListID aListID,
|
|
nsIFrame* aOldFrame)
|
|
{
|
|
nsresult rv = nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
|
if (mFrames.IsEmpty())
|
|
RemoveListener();
|
|
|
|
return rv;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::InsertFrames(ChildListID aListID,
|
|
nsIFrame* aPrevFrame,
|
|
nsFrameList& aFrameList)
|
|
{
|
|
bool wasEmpty = mFrames.IsEmpty();
|
|
nsresult rv = nsBoxFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
|
if (wasEmpty)
|
|
AddListener();
|
|
|
|
return rv;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::AppendFrames(ChildListID aListID,
|
|
nsFrameList& aFrameList)
|
|
{
|
|
// if we have no children and on was added then make sure we add the
|
|
// listener
|
|
bool wasEmpty = mFrames.IsEmpty();
|
|
nsresult rv = nsBoxFrame::AppendFrames(aListID, aFrameList);
|
|
if (wasEmpty)
|
|
AddListener();
|
|
|
|
return rv;
|
|
}
|
|
|
|
int32_t
|
|
nsSliderFrame::GetCurrentPosition(nsIContent* content)
|
|
{
|
|
return GetIntegerAttribute(content, nsGkAtoms::curpos, 0);
|
|
}
|
|
|
|
int32_t
|
|
nsSliderFrame::GetMinPosition(nsIContent* content)
|
|
{
|
|
return GetIntegerAttribute(content, nsGkAtoms::minpos, 0);
|
|
}
|
|
|
|
int32_t
|
|
nsSliderFrame::GetMaxPosition(nsIContent* content)
|
|
{
|
|
return GetIntegerAttribute(content, nsGkAtoms::maxpos, 100);
|
|
}
|
|
|
|
int32_t
|
|
nsSliderFrame::GetIncrement(nsIContent* content)
|
|
{
|
|
return GetIntegerAttribute(content, nsGkAtoms::increment, 1);
|
|
}
|
|
|
|
|
|
int32_t
|
|
nsSliderFrame::GetPageIncrement(nsIContent* content)
|
|
{
|
|
return GetIntegerAttribute(content, nsGkAtoms::pageincrement, 10);
|
|
}
|
|
|
|
int32_t
|
|
nsSliderFrame::GetIntegerAttribute(nsIContent* content, nsIAtom* atom, int32_t defaultValue)
|
|
{
|
|
nsAutoString value;
|
|
content->GetAttr(kNameSpaceID_None, atom, value);
|
|
if (!value.IsEmpty()) {
|
|
nsresult error;
|
|
|
|
// convert it to an integer
|
|
defaultValue = value.ToInteger(&error);
|
|
}
|
|
|
|
return defaultValue;
|
|
}
|
|
|
|
class nsValueChangedRunnable : public nsRunnable
|
|
{
|
|
public:
|
|
nsValueChangedRunnable(nsISliderListener* aListener,
|
|
nsIAtom* aWhich,
|
|
int32_t aValue,
|
|
bool aUserChanged)
|
|
: mListener(aListener), mWhich(aWhich),
|
|
mValue(aValue), mUserChanged(aUserChanged)
|
|
{}
|
|
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
return mListener->ValueChanged(nsDependentAtomString(mWhich),
|
|
mValue, mUserChanged);
|
|
}
|
|
|
|
nsCOMPtr<nsISliderListener> mListener;
|
|
nsCOMPtr<nsIAtom> mWhich;
|
|
int32_t mValue;
|
|
bool mUserChanged;
|
|
};
|
|
|
|
class nsDragStateChangedRunnable : public nsRunnable
|
|
{
|
|
public:
|
|
nsDragStateChangedRunnable(nsISliderListener* aListener,
|
|
bool aDragBeginning)
|
|
: mListener(aListener),
|
|
mDragBeginning(aDragBeginning)
|
|
{}
|
|
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
return mListener->DragStateChanged(mDragBeginning);
|
|
}
|
|
|
|
nsCOMPtr<nsISliderListener> mListener;
|
|
bool mDragBeginning;
|
|
};
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::AttributeChanged(int32_t aNameSpaceID,
|
|
nsIAtom* aAttribute,
|
|
int32_t aModType)
|
|
{
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
aModType);
|
|
// if the current position changes
|
|
if (aAttribute == nsGkAtoms::curpos) {
|
|
CurrentPositionChanged();
|
|
} else if (aAttribute == nsGkAtoms::minpos ||
|
|
aAttribute == nsGkAtoms::maxpos) {
|
|
// bounds check it.
|
|
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
nsCOMPtr<nsIContent> scrollbar;
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
|
int32_t current = GetCurrentPosition(scrollbar);
|
|
int32_t min = GetMinPosition(scrollbar);
|
|
int32_t max = GetMaxPosition(scrollbar);
|
|
|
|
// inform the parent <scale> that the minimum or maximum changed
|
|
nsIFrame* parent = GetParent();
|
|
if (parent) {
|
|
nsCOMPtr<nsISliderListener> sliderListener = do_QueryInterface(parent->GetContent());
|
|
if (sliderListener) {
|
|
nsContentUtils::AddScriptRunner(
|
|
new nsValueChangedRunnable(sliderListener, aAttribute,
|
|
aAttribute == nsGkAtoms::minpos ? min : max, false));
|
|
}
|
|
}
|
|
|
|
if (current < min || current > max)
|
|
{
|
|
if (current < min || max < min)
|
|
current = min;
|
|
else if (current > max)
|
|
current = max;
|
|
|
|
// set the new position and notify observers
|
|
nsScrollbarFrame* scrollbarFrame = do_QueryFrame(scrollbarBox);
|
|
if (scrollbarFrame) {
|
|
nsIScrollbarMediator* mediator = scrollbarFrame->GetScrollbarMediator();
|
|
if (mediator) {
|
|
mediator->PositionChanged(scrollbarFrame, GetCurrentPosition(scrollbar), current);
|
|
}
|
|
}
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
new nsSetAttrRunnable(scrollbar, nsGkAtoms::curpos, current));
|
|
}
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::minpos ||
|
|
aAttribute == nsGkAtoms::maxpos ||
|
|
aAttribute == nsGkAtoms::pageincrement ||
|
|
aAttribute == nsGkAtoms::increment) {
|
|
|
|
PresContext()->PresShell()->
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
const nsRect& aDirtyRect,
|
|
const nsDisplayListSet& aLists)
|
|
{
|
|
if (aBuilder->IsForEventDelivery() && isDraggingThumb()) {
|
|
// This is EVIL, we shouldn't be messing with event delivery just to get
|
|
// thumb mouse drag events to arrive at the slider!
|
|
aLists.Outlines()->AppendNewToTop(new (aBuilder)
|
|
nsDisplayEventReceiver(aBuilder, this));
|
|
return;
|
|
}
|
|
|
|
nsBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
const nsRect& aDirtyRect,
|
|
const nsDisplayListSet& aLists)
|
|
{
|
|
// if we are too small to have a thumb don't paint it.
|
|
nsIFrame* thumb = GetChildBox();
|
|
|
|
if (thumb) {
|
|
nsRect thumbRect(thumb->GetRect());
|
|
nsMargin m;
|
|
thumb->GetMargin(m);
|
|
thumbRect.Inflate(m);
|
|
|
|
nsRect crect;
|
|
GetClientRect(crect);
|
|
|
|
if (crect.width < thumbRect.width || crect.height < thumbRect.height)
|
|
return;
|
|
}
|
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::DoLayout(nsBoxLayoutState& aState)
|
|
{
|
|
// get the thumb should be our only child
|
|
nsIFrame* thumbBox = GetChildBox();
|
|
|
|
if (!thumbBox) {
|
|
SyncLayout(aState);
|
|
return NS_OK;
|
|
}
|
|
|
|
EnsureOrient();
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
if (mState & NS_STATE_DEBUG_WAS_SET) {
|
|
if (mState & NS_STATE_SET_TO_DEBUG)
|
|
SetDebug(aState, true);
|
|
else
|
|
SetDebug(aState, false);
|
|
}
|
|
#endif
|
|
|
|
// get the content area inside our borders
|
|
nsRect clientRect;
|
|
GetClientRect(clientRect);
|
|
|
|
// get the scrollbar
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
nsCOMPtr<nsIContent> scrollbar;
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
|
|
|
// get the thumb's pref size
|
|
nsSize thumbSize = thumbBox->GetPrefSize(aState);
|
|
|
|
if (IsHorizontal())
|
|
thumbSize.height = clientRect.height;
|
|
else
|
|
thumbSize.width = clientRect.width;
|
|
|
|
int32_t curPos = GetCurrentPosition(scrollbar);
|
|
int32_t minPos = GetMinPosition(scrollbar);
|
|
int32_t maxPos = GetMaxPosition(scrollbar);
|
|
int32_t pageIncrement = GetPageIncrement(scrollbar);
|
|
|
|
maxPos = std::max(minPos, maxPos);
|
|
curPos = clamped(curPos, minPos, maxPos);
|
|
|
|
nscoord& availableLength = IsHorizontal() ? clientRect.width : clientRect.height;
|
|
nscoord& thumbLength = IsHorizontal() ? thumbSize.width : thumbSize.height;
|
|
|
|
if ((pageIncrement + maxPos - minPos) > 0 && thumbBox->GetFlex(aState) > 0) {
|
|
float ratio = float(pageIncrement) / float(maxPos - minPos + pageIncrement);
|
|
thumbLength = std::max(thumbLength, NSToCoordRound(availableLength * ratio));
|
|
}
|
|
|
|
// Round the thumb's length to device pixels.
|
|
nsPresContext* presContext = PresContext();
|
|
thumbLength = presContext->DevPixelsToAppUnits(
|
|
presContext->AppUnitsToDevPixels(thumbLength));
|
|
|
|
// mRatio translates the thumb position in app units to the value.
|
|
mRatio = (minPos != maxPos) ? float(availableLength - thumbLength) / float(maxPos - minPos) : 1;
|
|
|
|
// in reverse mode, curpos is reversed such that lower values are to the
|
|
// right or bottom and increase leftwards or upwards. In this case, use the
|
|
// offset from the end instead of the beginning.
|
|
bool reverse = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
|
|
nsGkAtoms::reverse, eCaseMatters);
|
|
nscoord pos = reverse ? (maxPos - curPos) : (curPos - minPos);
|
|
|
|
// set the thumb's coord to be the current pos * the ratio.
|
|
nsRect thumbRect(clientRect.x, clientRect.y, thumbSize.width, thumbSize.height);
|
|
int32_t& thumbPos = (IsHorizontal() ? thumbRect.x : thumbRect.y);
|
|
thumbPos += NSToCoordRound(pos * mRatio);
|
|
|
|
nsRect oldThumbRect(thumbBox->GetRect());
|
|
LayoutChildAt(aState, thumbBox, thumbRect);
|
|
|
|
SyncLayout(aState);
|
|
|
|
// Redraw only if thumb changed size.
|
|
if (!oldThumbRect.IsEqualInterior(thumbRect))
|
|
Redraw(aState);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::HandleEvent(nsPresContext* aPresContext,
|
|
WidgetGUIEvent* aEvent,
|
|
nsEventStatus* aEventStatus)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
// If a web page calls event.preventDefault() we still want to
|
|
// scroll when scroll arrow is clicked. See bug 511075.
|
|
if (!mContent->IsInNativeAnonymousSubtree() &&
|
|
nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
nsCOMPtr<nsIContent> scrollbar;
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
|
bool isHorizontal = IsHorizontal();
|
|
|
|
if (isDraggingThumb())
|
|
{
|
|
switch (aEvent->message) {
|
|
case NS_TOUCH_MOVE:
|
|
case NS_MOUSE_MOVE: {
|
|
nsPoint eventPoint;
|
|
if (!GetEventPoint(aEvent, eventPoint)) {
|
|
break;
|
|
}
|
|
if (mChange) {
|
|
// We're in the process of moving the thumb to the mouse,
|
|
// but the mouse just moved. Make sure to update our
|
|
// destination point.
|
|
mDestinationPoint = eventPoint;
|
|
StopRepeat();
|
|
StartRepeat();
|
|
break;
|
|
}
|
|
|
|
nscoord pos = isHorizontal ? eventPoint.x : eventPoint.y;
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// take our current position and subtract the start location
|
|
pos -= mDragStart;
|
|
bool isMouseOutsideThumb = false;
|
|
if (gSnapMultiplier) {
|
|
nsSize thumbSize = thumbFrame->GetSize();
|
|
if (isHorizontal) {
|
|
// horizontal scrollbar - check if mouse is above or below thumb
|
|
// XXXbz what about looking at the .y of the thumb's rect? Is that
|
|
// always zero here?
|
|
if (eventPoint.y < -gSnapMultiplier * thumbSize.height ||
|
|
eventPoint.y > thumbSize.height +
|
|
gSnapMultiplier * thumbSize.height)
|
|
isMouseOutsideThumb = true;
|
|
}
|
|
else {
|
|
// vertical scrollbar - check if mouse is left or right of thumb
|
|
if (eventPoint.x < -gSnapMultiplier * thumbSize.width ||
|
|
eventPoint.x > thumbSize.width +
|
|
gSnapMultiplier * thumbSize.width)
|
|
isMouseOutsideThumb = true;
|
|
}
|
|
}
|
|
if (aEvent->eventStructType == NS_TOUCH_EVENT) {
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
}
|
|
if (isMouseOutsideThumb)
|
|
{
|
|
SetCurrentThumbPosition(scrollbar, mThumbStart, false, false);
|
|
return NS_OK;
|
|
}
|
|
|
|
// set it
|
|
SetCurrentThumbPosition(scrollbar, pos, false, true); // with snapping
|
|
}
|
|
break;
|
|
|
|
case NS_TOUCH_END:
|
|
case NS_MOUSE_BUTTON_UP:
|
|
if (ShouldScrollForEvent(aEvent)) {
|
|
// stop capturing
|
|
AddListener();
|
|
DragThumb(false);
|
|
if (mChange) {
|
|
StopRepeat();
|
|
mChange = 0;
|
|
}
|
|
//we MUST call nsFrame HandleEvent for mouse ups to maintain the selection state and capture state.
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
}
|
|
}
|
|
|
|
//return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
return NS_OK;
|
|
} else if (ShouldScrollToClickForEvent(aEvent)) {
|
|
nsPoint eventPoint;
|
|
if (!GetEventPoint(aEvent, eventPoint)) {
|
|
return NS_OK;
|
|
}
|
|
nscoord pos = isHorizontal ? eventPoint.x : eventPoint.y;
|
|
|
|
// adjust so that the middle of the thumb is placed under the click
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
return NS_OK;
|
|
}
|
|
nsSize thumbSize = thumbFrame->GetSize();
|
|
nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height;
|
|
|
|
// set it
|
|
nsWeakFrame weakFrame(this);
|
|
// should aMaySnap be true here?
|
|
SetCurrentThumbPosition(scrollbar, pos - thumbLength/2, false, false);
|
|
NS_ENSURE_TRUE(weakFrame.IsAlive(), NS_OK);
|
|
|
|
DragThumb(true);
|
|
if (aEvent->eventStructType == NS_TOUCH_EVENT) {
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
}
|
|
|
|
if (isHorizontal)
|
|
mThumbStart = thumbFrame->GetPosition().x;
|
|
else
|
|
mThumbStart = thumbFrame->GetPosition().y;
|
|
|
|
mDragStart = pos - mThumbStart;
|
|
}
|
|
|
|
// XXX hack until handle release is actually called in nsframe.
|
|
// if (aEvent->message == NS_MOUSE_EXIT_SYNTH || aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP || aEvent->message == NS_MOUSE_LEFT_BUTTON_UP)
|
|
// HandleRelease(aPresContext, aEvent, aEventStatus);
|
|
|
|
if (aEvent->message == NS_MOUSE_EXIT_SYNTH && mChange)
|
|
HandleRelease(aPresContext, aEvent, aEventStatus);
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
}
|
|
|
|
// Helper function to collect the "scroll to click" metric. Beware of
|
|
// caching this, users expect to be able to change the system preference
|
|
// and see the browser change its behavior immediately.
|
|
bool
|
|
nsSliderFrame::GetScrollToClick()
|
|
{
|
|
if (GetScrollbar() != this) {
|
|
return LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollToClick, false);
|
|
}
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::movetoclick,
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
return true;
|
|
}
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::movetoclick,
|
|
nsGkAtoms::_false, eCaseMatters)) {
|
|
return false;
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
nsIFrame*
|
|
nsSliderFrame::GetScrollbar()
|
|
{
|
|
// if we are in a scrollbar then return the scrollbar's content node
|
|
// if we are not then return ours.
|
|
nsIFrame* scrollbar;
|
|
nsScrollbarButtonFrame::GetParentWithTag(nsGkAtoms::scrollbar, this, scrollbar);
|
|
|
|
if (scrollbar == nullptr)
|
|
return this;
|
|
|
|
return scrollbar->IsBoxFrame() ? scrollbar : this;
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::PageUpDown(nscoord change)
|
|
{
|
|
// on a page up or down get our page increment. We get this by getting the scrollbar we are in and
|
|
// asking it for the current position and the page increment. If we are not in a scrollbar we will
|
|
// get the values from our own node.
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
nsCOMPtr<nsIContent> scrollbar;
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
|
|
nsGkAtoms::reverse, eCaseMatters))
|
|
change = -change;
|
|
|
|
nscoord pageIncrement = GetPageIncrement(scrollbar);
|
|
int32_t curpos = GetCurrentPosition(scrollbar);
|
|
int32_t minpos = GetMinPosition(scrollbar);
|
|
int32_t maxpos = GetMaxPosition(scrollbar);
|
|
|
|
// get the new position and make sure it is in bounds
|
|
int32_t newpos = curpos + change * pageIncrement;
|
|
if (newpos < minpos || maxpos < minpos)
|
|
newpos = minpos;
|
|
else if (newpos > maxpos)
|
|
newpos = maxpos;
|
|
|
|
SetCurrentPositionInternal(scrollbar, newpos, true);
|
|
}
|
|
|
|
// called when the current position changed and we need to update the thumb's location
|
|
void
|
|
nsSliderFrame::CurrentPositionChanged()
|
|
{
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
nsCOMPtr<nsIContent> scrollbar;
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
|
|
|
// get the current position
|
|
int32_t curPos = GetCurrentPosition(scrollbar);
|
|
|
|
// do nothing if the position did not change
|
|
if (mCurPos == curPos)
|
|
return;
|
|
|
|
// get our current min and max position from our content node
|
|
int32_t minPos = GetMinPosition(scrollbar);
|
|
int32_t maxPos = GetMaxPosition(scrollbar);
|
|
|
|
maxPos = std::max(minPos, maxPos);
|
|
curPos = clamped(curPos, minPos, maxPos);
|
|
|
|
// get the thumb's rect
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame)
|
|
return; // The thumb may stream in asynchronously via XBL.
|
|
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
|
|
|
nsRect clientRect;
|
|
GetClientRect(clientRect);
|
|
|
|
// figure out the new rect
|
|
nsRect newThumbRect(thumbRect);
|
|
|
|
bool reverse = mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
|
|
nsGkAtoms::reverse, eCaseMatters);
|
|
nscoord pos = reverse ? (maxPos - curPos) : (curPos - minPos);
|
|
|
|
if (IsHorizontal())
|
|
newThumbRect.x = clientRect.x + NSToCoordRound(pos * mRatio);
|
|
else
|
|
newThumbRect.y = clientRect.y + NSToCoordRound(pos * mRatio);
|
|
|
|
// set the rect
|
|
thumbFrame->SetRect(newThumbRect);
|
|
|
|
// Request a repaint of the scrollbar
|
|
SchedulePaint();
|
|
|
|
mCurPos = curPos;
|
|
|
|
// inform the parent <scale> if it exists that the value changed
|
|
nsIFrame* parent = GetParent();
|
|
if (parent) {
|
|
nsCOMPtr<nsISliderListener> sliderListener = do_QueryInterface(parent->GetContent());
|
|
if (sliderListener) {
|
|
nsContentUtils::AddScriptRunner(
|
|
new nsValueChangedRunnable(sliderListener, nsGkAtoms::curpos, mCurPos, mUserChanged));
|
|
}
|
|
}
|
|
}
|
|
|
|
static void UpdateAttribute(nsIContent* aScrollbar, nscoord aNewPos, bool aNotify, bool aIsSmooth) {
|
|
nsAutoString str;
|
|
str.AppendInt(aNewPos);
|
|
|
|
if (aIsSmooth) {
|
|
aScrollbar->SetAttr(kNameSpaceID_None, nsGkAtoms::smooth, NS_LITERAL_STRING("true"), false);
|
|
}
|
|
aScrollbar->SetAttr(kNameSpaceID_None, nsGkAtoms::curpos, str, aNotify);
|
|
if (aIsSmooth) {
|
|
aScrollbar->UnsetAttr(kNameSpaceID_None, nsGkAtoms::smooth, false);
|
|
}
|
|
}
|
|
|
|
// Use this function when you want to set the scroll position via the position
|
|
// of the scrollbar thumb, e.g. when dragging the slider. This function scrolls
|
|
// the content in such a way that thumbRect.x/.y becomes aNewThumbPos.
|
|
void
|
|
nsSliderFrame::SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewThumbPos,
|
|
bool aIsSmooth, bool aMaySnap)
|
|
{
|
|
nsRect crect;
|
|
GetClientRect(crect);
|
|
nscoord offset = IsHorizontal() ? crect.x : crect.y;
|
|
int32_t newPos = NSToIntRound((aNewThumbPos - offset) / mRatio);
|
|
|
|
if (aMaySnap && mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::snap,
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
// If snap="true", then the slider may only be set to min + (increment * x).
|
|
// Otherwise, the slider may be set to any positive integer.
|
|
int32_t increment = GetIncrement(aScrollbar);
|
|
newPos = NSToIntRound(newPos / float(increment)) * increment;
|
|
}
|
|
|
|
SetCurrentPosition(aScrollbar, newPos, aIsSmooth);
|
|
}
|
|
|
|
// Use this function when you know the target scroll position of the scrolled content.
|
|
// aNewPos should be passed to this function as a position as if the minpos is 0.
|
|
// That is, the minpos will be added to the position by this function. In a reverse
|
|
// direction slider, the newpos should be the distance from the end.
|
|
void
|
|
nsSliderFrame::SetCurrentPosition(nsIContent* aScrollbar, int32_t aNewPos,
|
|
bool aIsSmooth)
|
|
{
|
|
// get min and max position from our content node
|
|
int32_t minpos = GetMinPosition(aScrollbar);
|
|
int32_t maxpos = GetMaxPosition(aScrollbar);
|
|
|
|
// in reverse direction sliders, flip the value so that it goes from
|
|
// right to left, or bottom to top.
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
|
|
nsGkAtoms::reverse, eCaseMatters))
|
|
aNewPos = maxpos - aNewPos;
|
|
else
|
|
aNewPos += minpos;
|
|
|
|
// get the new position and make sure it is in bounds
|
|
if (aNewPos < minpos || maxpos < minpos)
|
|
aNewPos = minpos;
|
|
else if (aNewPos > maxpos)
|
|
aNewPos = maxpos;
|
|
|
|
SetCurrentPositionInternal(aScrollbar, aNewPos, aIsSmooth);
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::SetCurrentPositionInternal(nsIContent* aScrollbar, int32_t aNewPos,
|
|
bool aIsSmooth)
|
|
{
|
|
nsCOMPtr<nsIContent> scrollbar = aScrollbar;
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
|
|
mUserChanged = true;
|
|
|
|
nsScrollbarFrame* scrollbarFrame = do_QueryFrame(scrollbarBox);
|
|
if (scrollbarFrame) {
|
|
// See if we have a mediator.
|
|
nsIScrollbarMediator* mediator = scrollbarFrame->GetScrollbarMediator();
|
|
if (mediator) {
|
|
nsRefPtr<nsPresContext> context = PresContext();
|
|
nsCOMPtr<nsIContent> content = GetContent();
|
|
mediator->PositionChanged(scrollbarFrame, GetCurrentPosition(scrollbar), aNewPos);
|
|
// 'mediator' might be dangling now...
|
|
UpdateAttribute(scrollbar, aNewPos, false, aIsSmooth);
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
|
if (frame && frame->GetType() == nsGkAtoms::sliderFrame) {
|
|
static_cast<nsSliderFrame*>(frame)->CurrentPositionChanged();
|
|
}
|
|
mUserChanged = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
UpdateAttribute(scrollbar, aNewPos, true, aIsSmooth);
|
|
mUserChanged = false;
|
|
|
|
#ifdef DEBUG_SLIDER
|
|
printf("Current Pos=%d\n",aNewPos);
|
|
#endif
|
|
|
|
}
|
|
|
|
nsIAtom*
|
|
nsSliderFrame::GetType() const
|
|
{
|
|
return nsGkAtoms::sliderFrame;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::SetInitialChildList(ChildListID aListID,
|
|
nsFrameList& aChildList)
|
|
{
|
|
nsresult r = nsBoxFrame::SetInitialChildList(aListID, aChildList);
|
|
|
|
AddListener();
|
|
|
|
return r;
|
|
}
|
|
|
|
nsresult
|
|
nsSliderMediator::HandleEvent(nsIDOMEvent* aEvent)
|
|
{
|
|
// Only process the event if the thumb is not being dragged.
|
|
if (mSlider && !mSlider->isDraggingThumb())
|
|
return mSlider->StartDrag(aEvent);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsSliderFrame::StartDrag(nsIDOMEvent* aEvent)
|
|
{
|
|
#ifdef DEBUG_SLIDER
|
|
printf("Begin dragging\n");
|
|
#endif
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
return NS_OK;
|
|
|
|
WidgetGUIEvent* event = aEvent->GetInternalNSEvent()->AsGUIEvent();
|
|
|
|
if (!ShouldScrollForEvent(event)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsPoint pt;
|
|
if (!GetEventPoint(event, pt)) {
|
|
return NS_OK;
|
|
}
|
|
bool isHorizontal = IsHorizontal();
|
|
nscoord pos = isHorizontal ? pt.x : pt.y;
|
|
|
|
// If we should scroll-to-click, first place the middle of the slider thumb
|
|
// under the mouse.
|
|
nsCOMPtr<nsIContent> scrollbar;
|
|
nscoord newpos = pos;
|
|
bool scrollToClick = ShouldScrollToClickForEvent(event);
|
|
if (scrollToClick) {
|
|
// adjust so that the middle of the thumb is placed under the click
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
return NS_OK;
|
|
}
|
|
nsSize thumbSize = thumbFrame->GetSize();
|
|
nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height;
|
|
|
|
newpos -= (thumbLength/2);
|
|
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
|
}
|
|
|
|
DragThumb(true);
|
|
|
|
if (scrollToClick) {
|
|
// should aMaySnap be true here?
|
|
SetCurrentThumbPosition(scrollbar, newpos, false, false);
|
|
}
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (isHorizontal)
|
|
mThumbStart = thumbFrame->GetPosition().x;
|
|
else
|
|
mThumbStart = thumbFrame->GetPosition().y;
|
|
|
|
mDragStart = pos - mThumbStart;
|
|
|
|
#ifdef DEBUG_SLIDER
|
|
printf("Pressed mDragStart=%d\n",mDragStart);
|
|
#endif
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::DragThumb(bool aGrabMouseEvents)
|
|
{
|
|
// inform the parent <scale> that a drag is beginning or ending
|
|
nsIFrame* parent = GetParent();
|
|
if (parent) {
|
|
nsCOMPtr<nsISliderListener> sliderListener = do_QueryInterface(parent->GetContent());
|
|
if (sliderListener) {
|
|
nsContentUtils::AddScriptRunner(
|
|
new nsDragStateChangedRunnable(sliderListener, aGrabMouseEvents));
|
|
}
|
|
}
|
|
|
|
nsIPresShell::SetCapturingContent(aGrabMouseEvents ? GetContent() : nullptr,
|
|
aGrabMouseEvents ? CAPTURE_IGNOREALLOWED : 0);
|
|
}
|
|
|
|
bool
|
|
nsSliderFrame::isDraggingThumb()
|
|
{
|
|
return (nsIPresShell::GetCapturingContent() == GetContent());
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::AddListener()
|
|
{
|
|
if (!mMediator) {
|
|
mMediator = new nsSliderMediator(this);
|
|
}
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
return;
|
|
}
|
|
thumbFrame->GetContent()->
|
|
AddSystemEventListener(NS_LITERAL_STRING("mousedown"), mMediator,
|
|
false, false);
|
|
thumbFrame->GetContent()->
|
|
AddSystemEventListener(NS_LITERAL_STRING("touchstart"), mMediator,
|
|
false, false);
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::RemoveListener()
|
|
{
|
|
NS_ASSERTION(mMediator, "No listener was ever added!!");
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame)
|
|
return;
|
|
|
|
thumbFrame->GetContent()->
|
|
RemoveSystemEventListener(NS_LITERAL_STRING("mousedown"), mMediator, false);
|
|
}
|
|
|
|
bool
|
|
nsSliderFrame::ShouldScrollForEvent(WidgetGUIEvent* aEvent)
|
|
{
|
|
switch (aEvent->message) {
|
|
case NS_TOUCH_START:
|
|
case NS_TOUCH_END:
|
|
return true;
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
case NS_MOUSE_BUTTON_UP: {
|
|
uint16_t button = aEvent->AsMouseEvent()->button;
|
|
return (button == WidgetMouseEvent::eLeftButton) ||
|
|
(button == WidgetMouseEvent::eMiddleButton && gMiddlePref);
|
|
}
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool
|
|
nsSliderFrame::ShouldScrollToClickForEvent(WidgetGUIEvent* aEvent)
|
|
{
|
|
if (!ShouldScrollForEvent(aEvent)) {
|
|
return false;
|
|
}
|
|
|
|
if (aEvent->message == NS_TOUCH_START) {
|
|
return GetScrollToClick();
|
|
}
|
|
|
|
if (aEvent->message != NS_MOUSE_BUTTON_DOWN) {
|
|
return false;
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
// On Mac, clicking the scrollbar thumb should never scroll to click.
|
|
if (IsEventOverThumb(aEvent)) {
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
if (mouseEvent->button == WidgetMouseEvent::eLeftButton) {
|
|
#ifdef XP_MACOSX
|
|
bool invertPref = mouseEvent->IsAlt();
|
|
#else
|
|
bool invertPref = mouseEvent->IsShift();
|
|
#endif
|
|
return GetScrollToClick() != invertPref;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
nsSliderFrame::IsEventOverThumb(WidgetGUIEvent* aEvent)
|
|
{
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
return false;
|
|
}
|
|
|
|
nsPoint eventPoint;
|
|
if (!GetEventPoint(aEvent, eventPoint)) {
|
|
return false;
|
|
}
|
|
|
|
bool isHorizontal = IsHorizontal();
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
|
nscoord eventPos = isHorizontal ? eventPoint.x : eventPoint.y;
|
|
nscoord thumbStart = isHorizontal ? thumbRect.x : thumbRect.y;
|
|
nscoord thumbEnd = isHorizontal ? thumbRect.XMost() : thumbRect.YMost();
|
|
|
|
return eventPos >= thumbStart && eventPos < thumbEnd;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::HandlePress(nsPresContext* aPresContext,
|
|
WidgetGUIEvent* aEvent,
|
|
nsEventStatus* aEventStatus)
|
|
{
|
|
if (!ShouldScrollForEvent(aEvent) || ShouldScrollToClickForEvent(aEvent)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (IsEventOverThumb(aEvent)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) // display:none?
|
|
return NS_OK;
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
return NS_OK;
|
|
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
|
|
|
nscoord change = 1;
|
|
nsPoint eventPoint;
|
|
if (!GetEventPoint(aEvent, eventPoint)) {
|
|
return NS_OK;
|
|
}
|
|
if (IsHorizontal() ? eventPoint.x < thumbRect.x
|
|
: eventPoint.y < thumbRect.y)
|
|
change = -1;
|
|
|
|
mChange = change;
|
|
DragThumb(true);
|
|
mDestinationPoint = eventPoint;
|
|
StartRepeat();
|
|
PageUpDown(change);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsSliderFrame::HandleRelease(nsPresContext* aPresContext,
|
|
WidgetGUIEvent* aEvent,
|
|
nsEventStatus* aEventStatus)
|
|
{
|
|
StopRepeat();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
{
|
|
// tell our mediator if we have one we are gone.
|
|
if (mMediator) {
|
|
mMediator->SetSlider(nullptr);
|
|
mMediator = nullptr;
|
|
}
|
|
StopRepeat();
|
|
|
|
// call base class Destroy()
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
|
}
|
|
|
|
nsSize
|
|
nsSliderFrame::GetPrefSize(nsBoxLayoutState& aState)
|
|
{
|
|
EnsureOrient();
|
|
return nsBoxFrame::GetPrefSize(aState);
|
|
}
|
|
|
|
nsSize
|
|
nsSliderFrame::GetMinSize(nsBoxLayoutState& aState)
|
|
{
|
|
EnsureOrient();
|
|
|
|
// our min size is just our borders and padding
|
|
return nsBox::GetMinSize(aState);
|
|
}
|
|
|
|
nsSize
|
|
nsSliderFrame::GetMaxSize(nsBoxLayoutState& aState)
|
|
{
|
|
EnsureOrient();
|
|
return nsBoxFrame::GetMaxSize(aState);
|
|
}
|
|
|
|
void
|
|
nsSliderFrame::EnsureOrient()
|
|
{
|
|
nsIFrame* scrollbarBox = GetScrollbar();
|
|
|
|
bool isHorizontal = (scrollbarBox->GetStateBits() & NS_STATE_IS_HORIZONTAL) != 0;
|
|
if (isHorizontal)
|
|
mState |= NS_STATE_IS_HORIZONTAL;
|
|
else
|
|
mState &= ~NS_STATE_IS_HORIZONTAL;
|
|
}
|
|
|
|
|
|
void nsSliderFrame::Notify(void)
|
|
{
|
|
bool stop = false;
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
if (!thumbFrame) {
|
|
StopRepeat();
|
|
return;
|
|
}
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
|
|
|
bool isHorizontal = IsHorizontal();
|
|
|
|
// See if the thumb has moved past our destination point.
|
|
// if it has we want to stop.
|
|
if (isHorizontal) {
|
|
if (mChange < 0) {
|
|
if (thumbRect.x < mDestinationPoint.x)
|
|
stop = true;
|
|
} else {
|
|
if (thumbRect.x + thumbRect.width > mDestinationPoint.x)
|
|
stop = true;
|
|
}
|
|
} else {
|
|
if (mChange < 0) {
|
|
if (thumbRect.y < mDestinationPoint.y)
|
|
stop = true;
|
|
} else {
|
|
if (thumbRect.y + thumbRect.height > mDestinationPoint.y)
|
|
stop = true;
|
|
}
|
|
}
|
|
|
|
|
|
if (stop) {
|
|
StopRepeat();
|
|
} else {
|
|
PageUpDown(mChange);
|
|
}
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS1(nsSliderMediator,
|
|
nsIDOMEventListener)
|