2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-04-20 21:39:52 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-04-20 21:39:52 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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.
|
1999-04-20 21:39:52 +00:00
|
|
|
*
|
1999-06-15 04:02:43 +00:00
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-06-03 02:12:19 +00:00
|
|
|
*
|
2001-07-15 00:05:20 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Dean Tessman <dean_tessman@hotmail.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-04-20 21:39:52 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
1999-04-20 21:39:52 +00:00
|
|
|
|
1999-04-20 21:43:09 +00:00
|
|
|
#include "nsSliderFrame.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1999-06-15 04:02:43 +00:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsUnitConversion.h"
|
1999-04-20 21:39:52 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-06-15 04:02:43 +00:00
|
|
|
#include "nsXULAtoms.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsStyleChangeList.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
#include "nsIViewManager.h"
|
2001-10-07 06:32:36 +00:00
|
|
|
#include "nsIWidget.h"
|
1999-11-03 07:11:45 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIDocument.h"
|
1999-06-15 04:02:43 +00:00
|
|
|
#include "nsScrollbarButtonFrame.h"
|
1999-06-23 17:00:17 +00:00
|
|
|
#include "nsIScrollbarListener.h"
|
2000-06-06 23:13:05 +00:00
|
|
|
#include "nsIScrollbarMediator.h"
|
|
|
|
#include "nsIScrollbarFrame.h"
|
1999-06-30 22:17:43 +00:00
|
|
|
#include "nsISupportsArray.h"
|
1999-08-19 22:16:23 +00:00
|
|
|
#include "nsXULAtoms.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsRepeatService.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-05-22 23:23:04 +00:00
|
|
|
#include "nsSprocketLayout.h"
|
2002-12-10 23:41:12 +00:00
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
2000-06-03 02:07:52 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2004-01-27 05:19:57 +00:00
|
|
|
PRBool nsSliderFrame::gMiddlePref = PR_FALSE;
|
|
|
|
PRInt32 nsSliderFrame::gSnapMultiplier = 6;
|
|
|
|
|
2002-11-26 21:38:18 +00:00
|
|
|
// Turn this on if you want to debug slider frames.
|
|
|
|
#undef DEBUG_SLIDER
|
1999-10-12 00:16:06 +00:00
|
|
|
|
2003-06-02 02:39:26 +00:00
|
|
|
static already_AddRefed<nsIContent>
|
|
|
|
GetContentOfBox(nsIBox *aBox)
|
|
|
|
{
|
|
|
|
nsIFrame *frame;
|
|
|
|
aBox->GetFrame(&frame);
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
NS_IF_ADDREF(content);
|
2003-06-02 02:39:26 +00:00
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
1999-04-20 21:39:52 +00:00
|
|
|
nsresult
|
1999-12-04 23:49:50 +00:00
|
|
|
NS_NewSliderFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-04-20 21:39:52 +00:00
|
|
|
{
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
nsSliderFrame* it = new (aPresShell) nsSliderFrame(aPresShell);
|
1999-06-15 04:02:43 +00:00
|
|
|
if (nsnull == it)
|
1999-04-20 21:39:52 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
1999-05-11 22:03:29 +00:00
|
|
|
*aNewFrame = it;
|
1999-04-20 21:39:52 +00:00
|
|
|
return NS_OK;
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
} // NS_NewSliderFrame
|
1999-04-20 21:39:52 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsSliderFrame::nsSliderFrame(nsIPresShell* aPresShell):nsBoxFrame(aPresShell),
|
2000-04-26 04:00:29 +00:00
|
|
|
mCurPos(0), mScrollbarListener(nsnull),mChange(0), mMediator(nsnull)
|
1999-04-20 21:39:52 +00:00
|
|
|
{
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
1999-04-20 21:39:52 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
// stop timer
|
|
|
|
nsSliderFrame::~nsSliderFrame()
|
|
|
|
{
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
mRedrawImmediate = PR_FALSE;
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSliderFrame::Init(nsIPresContext* aPresContext,
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aContext,
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIFrame* aPrevInFlow)
|
1999-04-20 21:39:52 +00:00
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2004-01-27 05:19:57 +00:00
|
|
|
static PRBool gotPrefs = PR_FALSE;
|
|
|
|
if (!gotPrefs) {
|
|
|
|
gotPrefs = PR_TRUE;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->GetBoolPref("middlemouse.scrollbarPosition", &gMiddlePref);
|
|
|
|
prefBranch->GetIntPref("slider.snapMultiplier", &gSnapMultiplier);
|
|
|
|
}
|
2001-07-18 23:19:42 +00:00
|
|
|
}
|
2000-06-03 02:07:52 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = GetView();
|
|
|
|
view->GetViewManager()->SetViewContentTransparency(view, PR_TRUE);
|
1999-06-15 04:02:43 +00:00
|
|
|
return rv;
|
1999-04-20 21:39:52 +00:00
|
|
|
}
|
|
|
|
|
2001-01-11 01:56:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::RemoveFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::RemoveFrame(aPresContext, aPresShell, aListName, aOldFrame);
|
|
|
|
PRInt32 start = GetChildCount();
|
2001-07-15 00:05:20 +00:00
|
|
|
if (start == 0)
|
2001-01-11 01:56:27 +00:00
|
|
|
RemoveListener();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::InsertFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
PRInt32 start = GetChildCount();
|
|
|
|
nsresult rv = nsBoxFrame::InsertFrames(aPresContext, aPresShell, aListName, aPrevFrame, aFrameList);
|
2001-07-15 00:05:20 +00:00
|
|
|
if (start == 0)
|
2001-01-11 01:56:27 +00:00
|
|
|
AddListener();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::AppendFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
// if we have no children and on was added then make sure we add the
|
|
|
|
// listener
|
|
|
|
PRInt32 start = GetChildCount();
|
|
|
|
nsresult rv = nsBoxFrame::AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
|
2001-07-15 00:05:20 +00:00
|
|
|
if (start == 0)
|
2001-01-11 01:56:27 +00:00
|
|
|
AddListener();
|
|
|
|
|
|
|
|
return rv;
|
2001-07-15 00:05:20 +00:00
|
|
|
}
|
2001-01-11 01:56:27 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
PRInt32
|
|
|
|
nsSliderFrame::GetCurrentPosition(nsIContent* content)
|
|
|
|
{
|
|
|
|
return GetIntegerAttribute(content, nsXULAtoms::curpos, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsSliderFrame::GetMaxPosition(nsIContent* content)
|
|
|
|
{
|
|
|
|
return GetIntegerAttribute(content, nsXULAtoms::maxpos, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsSliderFrame::GetIncrement(nsIContent* content)
|
|
|
|
{
|
|
|
|
return GetIntegerAttribute(content, nsXULAtoms::increment, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsSliderFrame::GetPageIncrement(nsIContent* content)
|
|
|
|
{
|
|
|
|
return GetIntegerAttribute(content, nsXULAtoms::pageincrement, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsSliderFrame::GetIntegerAttribute(nsIContent* content, nsIAtom* atom, PRInt32 defaultValue)
|
|
|
|
{
|
Landing changes Vidur made while the tree was closed for beta1 work, here's a list of the changes. r=me
[1] Cutting down the size of content. Made nsIJSScriptObject inherit from nsIScriptObjectOwner
[2] Cutting down the size of content. Made nsITextContent inherit from nsIContent.
[3] Cutting down the size of content. Moved implementation of nsIDOMReceiver to nsListenerManager. This is not true aggregation since it isn't transitive, but it's OK for now. It will be necessary for nsListenerManager to have a reference to its content in the future anyway, so the transitivity could be done.
dom/public/nsDOMPropEnums.h,v - bug 12559
dom/public/nsIJSScriptObject.h,v - [1]
dom/public/html/MANIFEST,v - bug 12559
dom/public/html/Makefile.in,v - bug 12559
dom/public/html/makefile.win,v - bug 12559
dom/public/html/nsIDOMHTMLInputElement.h,v - bug 17544
dom/public/idl/html/HTMLAnchorElement.idl,v - bug 12559
dom/public/idl/html/HTMLAreaElement.idl,v - bug 12559
dom/public/idl/html/HTMLInputElement.idl,v - bug 17544
dom/src/base/nsGlobalWindow.cpp,v - bug 30700
dom/src/base/nsGlobalWindow.h,v - [1]
dom/src/base/nsLocation.cpp,v - [1]
dom/src/html/nsJSHTMLAnchorElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLAreaElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLInputElement.cpp,v - bug 17544
layout/base/public/nsIDocument.h,v - bug 27953
layout/base/public/nsITextContent.h,v - [2]
layout/base/src/nsCommentNode.cpp,v - [2]
layout/base/src/nsDocument.cpp,v - bug 27953
layout/base/src/nsDocument.h,v - bug 27953
layout/base/src/nsDocumentViewer.cpp,v - bug 27953
layout/base/src/nsGenericDOMDataNode.cpp,v - [3]
layout/base/src/nsGenericDOMDataNode.h,v - [3]
layout/base/src/nsGenericElement.cpp,v - [3]
layout/base/src/nsGenericElement.h,v - [3]
layout/base/src/nsNameSpaceManager.cpp,v - bug 7834
layout/base/src/nsStyleContext.cpp,v - outline property shouldn't reflow
layout/base/src/nsTextNode.cpp,v - [2]
layout/events/src/nsEventListenerManager.cpp,v - [3]
layout/events/src/nsEventListenerManager.h,v - [3]
layout/html/base/src/nsGfxScrollFrame.cpp,v - nsString->nsAutoString
layout/html/content/src/nsAttributeContent.cpp,v - [2]
layout/html/content/src/nsHTMLAnchorElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAppletElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBodyElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLButtonElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDirectoryElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDivElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLEmbedElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFieldSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFormElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadingElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHtmlElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLImageElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInputElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInsElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIsIndexElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLIElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLabelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLayerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLegendElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLinkElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMapElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMenuElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMetaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLModElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLObjectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParagraphElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParamElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLPreElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLQuoteElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLScriptElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSelectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpacerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpanElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLStyleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCaptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCellElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableRowElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableSectionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTextAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTitleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLUListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLWBRElement.cpp,v - [1][3]
layout/html/document/src/nsHTMLDocument.cpp,v - bug 27953
layout/html/document/src/nsHTMLDocument.h,v - bug 27953
layout/xml/content/src/nsXMLCDATASection.cpp,v - [1][2]
layout/xml/content/src/nsXMLDocumentType.cpp,v - [1][2]
layout/xml/content/src/nsXMLElement.h,v - [1][2]
layout/xml/content/src/nsXMLEntity.cpp,v - [1][2]
layout/xml/content/src/nsXMLNotation.cpp,v - [1][2]
layout/xml/content/src/nsXMLProcessingInstruction.cpp,v - [1][2]
layout/xul/base/src/nsBoxFrame.cpp,v - nsString->nsAutoString
layout/xul/base/src/nsSliderFrame.cpp,v - nsString->nsAutoString
netwerk/protocol/http/src/nsHTTPRequest.cpp,v - nsString->nsAutoString
rdf/content/src/nsXULDocument.cpp,v - bug 27953
rdf/content/src/nsXULDocument.h,v - bug 27953
rdf/content/src/nsXULElement.h,v - [1]
xpcom/base/IIDS.h,v - bug 12559
2000-03-17 13:27:00 +00:00
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, atom, value))
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
|
|
|
PRInt32 error;
|
|
|
|
|
|
|
|
// convert it to an integer
|
|
|
|
defaultValue = value.ToInteger(&error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
1999-10-15 23:16:45 +00:00
|
|
|
PRInt32 aNameSpaceID,
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-11 21:16:12 +00:00
|
|
|
PRInt32 aModType)
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aPresContext, aChild,
|
2003-07-11 21:16:12 +00:00
|
|
|
aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
1999-06-15 04:02:43 +00:00
|
|
|
// if the current position changes
|
|
|
|
if (aAttribute == nsXULAtoms::curpos) {
|
1999-10-20 00:46:21 +00:00
|
|
|
rv = CurrentPositionChanged(aPresContext);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to change position");
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-10-12 00:16:06 +00:00
|
|
|
} else if (aAttribute == nsXULAtoms::maxpos) {
|
|
|
|
// bounds check it.
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
2000-04-03 03:55:38 +00:00
|
|
|
nsCOMPtr<nsIContent> scrollbar;
|
2003-06-02 02:39:26 +00:00
|
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
2001-07-15 00:05:20 +00:00
|
|
|
PRInt32 current = GetCurrentPosition(scrollbar);
|
1999-10-12 00:16:06 +00:00
|
|
|
PRInt32 max = GetMaxPosition(scrollbar);
|
|
|
|
if (current < 0 || current > max)
|
|
|
|
{
|
2000-08-29 02:03:59 +00:00
|
|
|
if (current < 0)
|
|
|
|
current = 0;
|
2001-07-15 00:05:20 +00:00
|
|
|
else if (current > max)
|
2000-08-29 02:03:59 +00:00
|
|
|
current = max;
|
|
|
|
|
2003-04-14 14:34:45 +00:00
|
|
|
// set the new position and notify observers
|
2000-08-29 02:03:59 +00:00
|
|
|
nsCOMPtr<nsIScrollbarFrame> scrollbarFrame(do_QueryInterface(scrollbarBox));
|
|
|
|
if (scrollbarFrame) {
|
|
|
|
nsCOMPtr<nsIScrollbarMediator> mediator;
|
|
|
|
scrollbarFrame->GetScrollbarMediator(getter_AddRefs(mediator));
|
|
|
|
if (mediator) {
|
|
|
|
mediator->PositionChanged(GetCurrentPosition(scrollbar), current);
|
|
|
|
}
|
|
|
|
}
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2002-12-31 12:50:10 +00:00
|
|
|
nsAutoString currentStr;
|
|
|
|
currentStr.AppendInt(current);
|
2003-04-14 14:34:45 +00:00
|
|
|
scrollbar->SetAttr(kNameSpaceID_None, nsXULAtoms::curpos, currentStr, PR_TRUE);
|
1999-10-12 00:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2003-07-11 21:16:12 +00:00
|
|
|
if (aAttribute == nsXULAtoms::maxpos ||
|
|
|
|
aAttribute == nsXULAtoms::pageincrement ||
|
|
|
|
aAttribute == nsXULAtoms::increment) {
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsBoxLayoutState state(aPresContext);
|
|
|
|
MarkDirtyChildren(state);
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-09-19 12:35:19 +00:00
|
|
|
nsSliderFrame::Paint(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
1999-08-19 22:16:23 +00:00
|
|
|
// if we are too small to have a thumb don't paint it.
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox* thumb;
|
|
|
|
GetChildBox(&thumb);
|
|
|
|
|
2001-01-11 01:56:27 +00:00
|
|
|
if (thumb) {
|
|
|
|
nsRect thumbRect;
|
|
|
|
thumb->GetBounds(thumbRect);
|
|
|
|
nsMargin m;
|
|
|
|
thumb->GetMargin(m);
|
|
|
|
thumbRect.Inflate(m);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2001-01-11 01:56:27 +00:00
|
|
|
nsRect crect;
|
|
|
|
GetClientRect(crect);
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2001-01-11 01:56:27 +00:00
|
|
|
if (crect.width < thumbRect.width || crect.height < thumbRect.height)
|
|
|
|
{
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
2002-12-23 22:05:47 +00:00
|
|
|
PaintSelf(aPresContext, aRenderingContext, aDirtyRect);
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
2001-01-11 01:56:27 +00:00
|
|
|
return NS_OK;
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-11 01:56:27 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
return nsBoxFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
1999-04-20 21:39:52 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
2000-07-07 22:24:06 +00:00
|
|
|
nsSliderFrame::DoLayout(nsBoxLayoutState& aState)
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
2001-01-11 01:56:27 +00:00
|
|
|
// get the thumb should be our only child
|
|
|
|
nsIBox* thumbBox = nsnull;
|
|
|
|
GetChildBox(&thumbBox);
|
|
|
|
|
|
|
|
if (!thumbBox) {
|
|
|
|
SyncLayout(aState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
EnsureOrient();
|
|
|
|
|
|
|
|
if (mState & NS_STATE_DEBUG_WAS_SET) {
|
|
|
|
if (mState & NS_STATE_SET_TO_DEBUG)
|
2000-04-25 07:10:48 +00:00
|
|
|
SetDebug(aState, PR_TRUE);
|
2000-03-31 07:02:06 +00:00
|
|
|
else
|
2000-04-25 07:10:48 +00:00
|
|
|
SetDebug(aState, PR_FALSE);
|
1999-04-20 21:39:52 +00:00
|
|
|
}
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// get the content area inside our borders
|
|
|
|
nsRect clientRect(0,0,0,0);
|
|
|
|
GetClientRect(clientRect);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// get the scrollbar
|
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
2000-04-03 03:55:38 +00:00
|
|
|
nsCOMPtr<nsIContent> scrollbar;
|
2003-06-02 02:39:26 +00:00
|
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
2000-03-31 07:02:06 +00:00
|
|
|
PRBool isHorizontal = IsHorizontal();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// get the thumb's pref size
|
|
|
|
nsSize thumbSize(0,0);
|
2000-04-25 07:10:48 +00:00
|
|
|
thumbBox->GetPrefSize(aState, thumbSize);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
if (isHorizontal)
|
|
|
|
thumbSize.height = clientRect.height;
|
|
|
|
else
|
|
|
|
thumbSize.width = clientRect.width;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
// get our current position and max position from our content node
|
1999-08-19 22:16:23 +00:00
|
|
|
PRInt32 curpospx = GetCurrentPosition(scrollbar);
|
|
|
|
PRInt32 maxpospx = GetMaxPosition(scrollbar);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
if (curpospx < 0)
|
|
|
|
curpospx = 0;
|
|
|
|
else if (curpospx > maxpospx)
|
|
|
|
curpospx = maxpospx;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
float p2t;
|
2000-04-25 07:10:48 +00:00
|
|
|
aState.GetPresContext()->GetScaledPixelsToTwips(&p2t);
|
1999-06-15 04:02:43 +00:00
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
// get max pos in twips
|
|
|
|
nscoord maxpos = maxpospx*onePixel;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
// get our maxpos in twips. This is the space we have left over in the scrollbar
|
1999-06-15 04:02:43 +00:00
|
|
|
// after the height of the thumb has been removed
|
2000-03-31 07:02:06 +00:00
|
|
|
nscoord& desiredcoord = isHorizontal ? clientRect.width : clientRect.height;
|
1999-06-15 04:02:43 +00:00
|
|
|
nscoord& thumbcoord = isHorizontal ? thumbSize.width : thumbSize.height;
|
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
nscoord ourmaxpos = desiredcoord;
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2001-08-31 20:37:56 +00:00
|
|
|
mRatio = 1;
|
|
|
|
|
|
|
|
// its possible that our max position was set to 0. In that case the
|
|
|
|
// ratio should become 1 to avoid a divide by 0.
|
|
|
|
if (float(maxpos + ourmaxpos) != 0)
|
|
|
|
mRatio = float(ourmaxpos)/float(maxpos + ourmaxpos);
|
1999-08-19 22:16:23 +00:00
|
|
|
|
|
|
|
// if there is more room than the thumb need stretch the
|
|
|
|
// thumb
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2000-12-12 01:52:45 +00:00
|
|
|
nscoord flex = 0;
|
|
|
|
thumbBox->GetFlex(aState, flex);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
|
|
|
if (flex > 0)
|
2000-12-12 01:52:45 +00:00
|
|
|
{
|
|
|
|
nscoord thumbsize = NSToCoordRound(ourmaxpos * mRatio);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
if (thumbsize > thumbcoord)
|
2000-12-12 01:52:45 +00:00
|
|
|
{
|
|
|
|
// if the thumb is flexible make the thumb bigger.
|
|
|
|
if (isHorizontal)
|
2000-05-22 23:23:04 +00:00
|
|
|
thumbSize.width = thumbsize;
|
2000-03-31 07:02:06 +00:00
|
|
|
else
|
2001-08-31 20:37:56 +00:00
|
|
|
thumbSize.height = thumbsize;
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-12-12 01:52:45 +00:00
|
|
|
} else {
|
|
|
|
ourmaxpos -= thumbcoord;
|
2001-08-31 20:37:56 +00:00
|
|
|
if (float(maxpos) != 0)
|
|
|
|
mRatio = float(ourmaxpos)/float(maxpos);
|
2000-12-12 01:52:45 +00:00
|
|
|
}
|
1999-08-19 22:16:23 +00:00
|
|
|
} else {
|
2000-12-12 01:52:45 +00:00
|
|
|
ourmaxpos -= thumbcoord;
|
2001-08-31 20:37:56 +00:00
|
|
|
if (float(maxpos) != 0)
|
|
|
|
mRatio = float(ourmaxpos)/float(maxpos);
|
1999-04-20 21:39:52 +00:00
|
|
|
}
|
1999-08-19 22:16:23 +00:00
|
|
|
nscoord curpos = curpospx*onePixel;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
// set the thumbs y coord to be the current pos * the ratio.
|
1999-08-19 22:16:23 +00:00
|
|
|
nscoord pos = nscoord(float(curpos)*mRatio);
|
2000-03-31 07:02:06 +00:00
|
|
|
nsRect thumbRect(clientRect.x, clientRect.y, thumbSize.width, thumbSize.height);
|
2001-01-11 01:56:27 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
if (isHorizontal)
|
1999-08-19 22:16:23 +00:00
|
|
|
thumbRect.x += pos;
|
1999-06-15 04:02:43 +00:00
|
|
|
else
|
1999-08-19 22:16:23 +00:00
|
|
|
thumbRect.y += pos;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
nsRect oldThumbRect;
|
|
|
|
thumbBox->GetBounds(oldThumbRect);
|
2000-04-25 07:10:48 +00:00
|
|
|
LayoutChildAt(aState, thumbBox, thumbRect);
|
|
|
|
|
2001-01-11 01:56:27 +00:00
|
|
|
|
2000-04-25 07:10:48 +00:00
|
|
|
SyncLayout(aState);
|
1999-10-12 00:16:06 +00:00
|
|
|
|
2002-11-26 21:38:18 +00:00
|
|
|
#ifdef DEBUG_SLIDER
|
|
|
|
PRInt32 c = GetCurrentPosition(scrollbar);
|
|
|
|
PRInt32 m = GetMaxPosition(scrollbar);
|
|
|
|
printf("Current=%d, max=%d\n", c, m);
|
|
|
|
#endif
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
// redraw only if thumb changed size.
|
|
|
|
if (oldThumbRect != thumbRect)
|
|
|
|
Redraw(aState);
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-07-15 00:05:20 +00:00
|
|
|
nsSliderFrame::HandleEvent(nsIPresContext* aPresContext,
|
1999-06-15 04:02:43 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
2000-04-03 03:55:38 +00:00
|
|
|
nsCOMPtr<nsIContent> scrollbar;
|
2003-06-02 02:39:26 +00:00
|
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
2000-03-31 07:02:06 +00:00
|
|
|
PRBool isHorizontal = IsHorizontal();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2003-09-14 01:25:04 +00:00
|
|
|
if (isDraggingThumb())
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
// we want to draw immediately if the user doing it directly with the
|
|
|
|
// mouse that makes redrawing much faster.
|
|
|
|
mRedrawImmediate = PR_TRUE;
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE: {
|
|
|
|
// convert coord to pixels
|
|
|
|
nscoord pos = isHorizontal ? aEvent->point.x : aEvent->point.y;
|
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
// mDragStartPx is in pixels and is in our client areas coordinate system.
|
1999-06-28 19:57:28 +00:00
|
|
|
// so we need to first convert it so twips and then get it into our coordinate system.
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
// convert start to twips
|
|
|
|
nscoord startpx = mDragStartPx;
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
float p2t;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-06-15 04:02:43 +00:00
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
nscoord start = startpx*onePixel;
|
|
|
|
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
1999-06-28 19:57:28 +00:00
|
|
|
|
2002-03-06 01:52:06 +00:00
|
|
|
#ifdef OLD_SLIDER_FRAME_OFFSET_CALCULATION
|
1999-08-19 22:16:23 +00:00
|
|
|
|
1999-06-28 19:57:28 +00:00
|
|
|
// get it into our coordintate system by subtracting our parents offsets.
|
|
|
|
nsIFrame* parent = this;
|
|
|
|
while(parent != nsnull)
|
|
|
|
{
|
2001-10-07 06:32:36 +00:00
|
|
|
// if we hit a scrollable view make sure we take into account
|
|
|
|
// how much we are scrolled.
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = parent->GetView();
|
2001-10-07 06:32:36 +00:00
|
|
|
if (view) {
|
2003-06-19 23:44:01 +00:00
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
nsresult result = CallQueryInterface(view, &scrollingView);
|
2001-10-07 06:32:36 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nscoord xoff = 0;
|
|
|
|
nscoord yoff = 0;
|
|
|
|
scrollingView->GetScrollPosition(xoff, yoff);
|
|
|
|
isHorizontal ? start += xoff : start += yoff;
|
|
|
|
}
|
|
|
|
}
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsRect r = parent->GetRect();
|
1999-06-28 19:57:28 +00:00
|
|
|
isHorizontal ? start -= r.x : start -= r.y;
|
2001-10-07 06:32:36 +00:00
|
|
|
|
|
|
|
if (view) {
|
2003-08-04 12:39:51 +00:00
|
|
|
if (view->HasWidget()) {
|
2001-10-07 06:32:36 +00:00
|
|
|
nsWindowType windowType;
|
2003-08-04 12:39:51 +00:00
|
|
|
view->GetWidget()->GetWindowType(windowType);
|
2001-10-07 06:32:36 +00:00
|
|
|
if (windowType == eWindowType_popup)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
parent = parent->GetParent();
|
1999-06-28 19:57:28 +00:00
|
|
|
}
|
|
|
|
|
2002-03-06 01:52:06 +00:00
|
|
|
#else // Kin's new offset calculation code.
|
|
|
|
|
|
|
|
// start is relative to the upper left corner of the rootview's widget,
|
|
|
|
// unless the slider frame is in a popup, in which case it's relative
|
|
|
|
// to the upper left corner of the popup's widget. We need start to be
|
|
|
|
// in the coordinate system for the frame's contained view so that it
|
|
|
|
// matches aEvent->point's coordinate system.
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView *view = GetClosestView();
|
2002-03-06 01:52:06 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> rootWidget;
|
|
|
|
|
|
|
|
if (view) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIViewManager* vm = view->GetViewManager();
|
2002-03-06 01:52:06 +00:00
|
|
|
if (vm)
|
|
|
|
vm->GetWidget(getter_AddRefs(rootWidget));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view && rootWidget) {
|
|
|
|
// Now walk view's parent hierarchy, subtracting off the
|
|
|
|
// positions of each parent view, until we hit the view
|
|
|
|
// that contains the root or popup widget.
|
|
|
|
//
|
|
|
|
// When we're done, start should be in our contained
|
|
|
|
// view's coordinate system.
|
|
|
|
|
|
|
|
while (view) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIWidget* widget = view->GetWidget();
|
2002-03-06 01:52:06 +00:00
|
|
|
|
|
|
|
if (widget) {
|
|
|
|
nsWindowType windowType;
|
|
|
|
widget->GetWindowType(windowType);
|
|
|
|
|
|
|
|
if (widget == rootWidget || windowType == eWindowType_popup)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsPoint p = view->GetPosition();
|
|
|
|
start -= (isHorizontal ? p.x : p.y);
|
2002-03-06 01:52:06 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
view = view->GetParent();
|
2002-03-06 01:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // Kin's new offset calculation code.
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
//printf("Translated to start=%d\n",start);
|
1999-06-28 19:57:28 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
start -= mThumbStart;
|
|
|
|
|
|
|
|
// take our current position and substract the start location
|
|
|
|
pos -= start;
|
2001-07-15 00:05:20 +00:00
|
|
|
PRBool isMouseOutsideThumb = PR_FALSE;
|
2004-01-27 05:19:57 +00:00
|
|
|
if (gSnapMultiplier) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsSize thumbSize = thumbFrame->GetSize();
|
2001-07-18 23:19:42 +00:00
|
|
|
if (isHorizontal) {
|
|
|
|
// horizontal scrollbar - check if mouse is above or below thumb
|
2004-01-27 05:19:57 +00:00
|
|
|
if (aEvent->point.y < (-gSnapMultiplier * thumbSize.height) ||
|
|
|
|
aEvent->point.y > thumbSize.height + (gSnapMultiplier * thumbSize.height))
|
2001-07-18 23:19:42 +00:00
|
|
|
isMouseOutsideThumb = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// vertical scrollbar - check if mouse is left or right of thumb
|
2004-01-27 05:19:57 +00:00
|
|
|
if (aEvent->point.x < (-gSnapMultiplier * thumbSize.width) ||
|
|
|
|
aEvent->point.x > thumbSize.width + (gSnapMultiplier * thumbSize.width))
|
2001-07-18 23:19:42 +00:00
|
|
|
isMouseOutsideThumb = PR_TRUE;
|
|
|
|
}
|
2001-07-15 00:05:20 +00:00
|
|
|
}
|
|
|
|
if (isMouseOutsideThumb)
|
|
|
|
{
|
|
|
|
// XXX see bug 81586
|
2003-03-24 05:29:45 +00:00
|
|
|
SetCurrentPosition(scrollbar, thumbFrame, (int) (mThumbStart / onePixel / mRatio), PR_FALSE);
|
2001-07-15 00:05:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
// convert to pixels
|
|
|
|
nscoord pospx = pos/onePixel;
|
|
|
|
|
|
|
|
// convert to our internal coordinate system
|
|
|
|
pospx = nscoord(pospx/mRatio);
|
|
|
|
|
|
|
|
// set it
|
2003-03-24 05:29:45 +00:00
|
|
|
SetCurrentPosition(scrollbar, thumbFrame, pospx, PR_FALSE);
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
}
|
1999-06-15 04:02:43 +00:00
|
|
|
break;
|
|
|
|
|
2000-06-03 02:07:52 +00:00
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
2004-01-27 05:19:57 +00:00
|
|
|
if(!gMiddlePref)
|
2000-06-03 02:07:52 +00:00
|
|
|
break;
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
// stop capturing
|
2000-10-28 22:17:53 +00:00
|
|
|
//printf("stop capturing\n");
|
1999-06-15 04:02:43 +00:00
|
|
|
AddListener();
|
2003-09-14 01:25:04 +00:00
|
|
|
DragThumb(PR_FALSE);
|
2000-05-16 13:53:04 +00:00
|
|
|
mRedrawImmediate = PR_FALSE;//we MUST call nsFrame HandleEvent for mouse ups to maintain the selection state and capture state.
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
|
|
|
|
// we want to draw immediately if the user doing it directly with the
|
|
|
|
// mouse that makes redrawing much faster. Switch it back now.
|
|
|
|
mRedrawImmediate = PR_FALSE;
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
//return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
return NS_OK;
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
2003-11-24 23:52:49 +00:00
|
|
|
else if ((aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && ((nsMouseEvent *)aEvent)->isShift)
|
2004-01-27 05:19:57 +00:00
|
|
|
|| (gMiddlePref && aEvent->message == NS_MOUSE_MIDDLE_BUTTON_DOWN)) {
|
2000-06-03 02:07:52 +00:00
|
|
|
// convert coord from twips to pixels
|
|
|
|
nscoord pos = isHorizontal ? aEvent->point.x : aEvent->point.y;
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
nscoord pospx = pos/onePixel;
|
|
|
|
|
|
|
|
// adjust so that the middle of the thumb is placed under the click
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2003-08-04 12:39:51 +00:00
|
|
|
nsSize thumbSize = thumbFrame->GetSize();
|
2000-06-03 02:07:52 +00:00
|
|
|
nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height;
|
|
|
|
thumbLength /= onePixel;
|
|
|
|
pospx -= (thumbLength/2);
|
|
|
|
|
|
|
|
|
|
|
|
// convert to our internal coordinate system
|
|
|
|
pospx = nscoord(pospx/mRatio);
|
|
|
|
|
|
|
|
// set it
|
2003-03-24 05:29:45 +00:00
|
|
|
SetCurrentPosition(scrollbar, thumbFrame, pospx, PR_FALSE);
|
2000-06-03 02:07:52 +00:00
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
// hack to start dragging
|
2000-06-03 02:07:52 +00:00
|
|
|
|
|
|
|
nsIFrame* parent = this;
|
|
|
|
while(parent != nsnull)
|
|
|
|
{
|
|
|
|
// if we hit a scrollable view make sure we take into account
|
|
|
|
// how much we are scrolled.
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = parent->GetView();
|
2000-06-03 02:07:52 +00:00
|
|
|
if (view) {
|
2003-06-19 23:44:01 +00:00
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
nsresult result = CallQueryInterface(view, &scrollingView);
|
2000-06-03 02:07:52 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nscoord xoff = 0;
|
|
|
|
nscoord yoff = 0;
|
|
|
|
scrollingView->GetScrollPosition(xoff, yoff);
|
2001-07-15 00:05:20 +00:00
|
|
|
isHorizontal ? pos += xoff : pos += yoff;
|
2000-06-03 02:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsPoint p = parent->GetPosition();
|
|
|
|
pos += isHorizontal ? p.x : p.y;
|
|
|
|
parent = parent->GetParent();
|
2000-06-03 02:07:52 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 01:25:04 +00:00
|
|
|
DragThumb(PR_TRUE);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-06-03 02:07:52 +00:00
|
|
|
if (isHorizontal)
|
2003-08-04 12:39:51 +00:00
|
|
|
mThumbStart = thumbFrame->GetPosition().x;
|
2000-06-03 02:07:52 +00:00
|
|
|
else
|
2003-08-04 12:39:51 +00:00
|
|
|
mThumbStart = thumbFrame->GetPosition().y;
|
2000-06-03 02:07:52 +00:00
|
|
|
|
|
|
|
mDragStartPx =pos/onePixel;
|
|
|
|
}
|
2004-01-27 05:19:57 +00:00
|
|
|
else if (mChange != 0 && aEvent->message == NS_MOUSE_MOVE) {
|
|
|
|
// 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 = aEvent->point;
|
|
|
|
}
|
1999-06-15 04:02:43 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
// XXX hack until handle release is actually called in nsframe.
|
2000-04-26 04:00:29 +00:00
|
|
|
// 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 || aEvent->message == NS_MOUSE_LEFT_BUTTON_UP)
|
1999-08-19 22:16:23 +00:00
|
|
|
HandleRelease(aPresContext, aEvent, aEventStatus);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox*
|
|
|
|
nsSliderFrame::GetScrollbar()
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
|
|
|
// if we are in a scrollbar then return the scrollbar's content node
|
|
|
|
// if we are not then return ours.
|
|
|
|
nsIFrame* scrollbar;
|
|
|
|
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::scrollbar, this, scrollbar);
|
|
|
|
|
|
|
|
if (scrollbar == nsnull)
|
2000-03-31 07:02:06 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
nsIBox* ibox = nsnull;
|
|
|
|
scrollbar->QueryInterface(NS_GET_IID(nsIBox), (void**)&ibox);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
if (ibox == nsnull)
|
|
|
|
return this;
|
|
|
|
|
|
|
|
return ibox;
|
|
|
|
}
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
void
|
1999-08-19 22:16:23 +00:00
|
|
|
nsSliderFrame::PageUpDown(nsIFrame* aThumbFrame, nscoord change)
|
2001-07-15 00:05:20 +00:00
|
|
|
{
|
1999-06-15 04:02:43 +00:00
|
|
|
// 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.
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
2000-04-03 03:55:38 +00:00
|
|
|
nsCOMPtr<nsIContent> scrollbar;
|
2003-06-02 02:39:26 +00:00
|
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-23 17:00:17 +00:00
|
|
|
if (mScrollbarListener)
|
|
|
|
mScrollbarListener->PagedUpDown(); // Let the listener decide our increment.
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
nscoord pageIncrement = GetPageIncrement(scrollbar);
|
|
|
|
PRInt32 curpos = GetCurrentPosition(scrollbar);
|
2003-03-24 05:29:45 +00:00
|
|
|
SetCurrentPosition(scrollbar, aThumbFrame, curpos + change*pageIncrement, PR_TRUE);
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// called when the current position changed and we need to update the thumb's location
|
1999-10-20 00:46:21 +00:00
|
|
|
nsresult
|
1999-06-15 04:02:43 +00:00
|
|
|
nsSliderFrame::CurrentPositionChanged(nsIPresContext* aPresContext)
|
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
2000-04-03 03:55:38 +00:00
|
|
|
nsCOMPtr<nsIContent> scrollbar;
|
2003-06-02 02:39:26 +00:00
|
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
PRBool isHorizontal = IsHorizontal();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
// get the current position
|
|
|
|
PRInt32 curpos = GetCurrentPosition(scrollbar);
|
|
|
|
|
1999-10-12 00:16:06 +00:00
|
|
|
// do nothing if the position did not change
|
|
|
|
if (mCurPos == curpos)
|
1999-10-20 00:46:21 +00:00
|
|
|
return NS_OK;
|
1999-10-12 00:16:06 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
// get our current position and max position from our content node
|
|
|
|
PRInt32 maxpos = GetMaxPosition(scrollbar);
|
|
|
|
|
|
|
|
if (curpos < 0)
|
|
|
|
curpos = 0;
|
|
|
|
else if (curpos > maxpos)
|
|
|
|
curpos = maxpos;
|
|
|
|
|
|
|
|
// convert to pixels
|
|
|
|
float p2t;
|
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
|
|
|
|
nscoord curpospx = curpos*onePixel;
|
|
|
|
|
|
|
|
// get the thumb's rect
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2001-06-01 22:48:05 +00:00
|
|
|
if (!thumbFrame)
|
|
|
|
return NS_OK; // The thumb may stream in asynchronously via XBL.
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-08-30 21:51:02 +00:00
|
|
|
nsRect clientRect;
|
|
|
|
GetClientRect(clientRect);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
// figure out the new rect
|
|
|
|
nsRect newThumbRect(thumbRect);
|
|
|
|
|
|
|
|
if (isHorizontal)
|
2000-08-30 21:51:02 +00:00
|
|
|
newThumbRect.x = clientRect.x + nscoord(float(curpospx)*mRatio);
|
1999-06-15 04:02:43 +00:00
|
|
|
else
|
2000-08-30 21:51:02 +00:00
|
|
|
newThumbRect.y = clientRect.y + nscoord(float(curpospx)*mRatio);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
// set the rect
|
2003-08-04 12:39:51 +00:00
|
|
|
thumbFrame->SetRect(newThumbRect);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
// figure out the union of the rect so we know what to redraw
|
|
|
|
nsRect changeRect;
|
|
|
|
changeRect.UnionRect(thumbRect, newThumbRect);
|
|
|
|
|
2001-11-06 01:44:20 +00:00
|
|
|
if (!changeRect.IsEmpty()) {
|
|
|
|
// redraw just the change
|
|
|
|
Invalidate(aPresContext, changeRect, mRedrawImmediate);
|
|
|
|
}
|
|
|
|
|
1999-06-23 17:00:17 +00:00
|
|
|
if (mScrollbarListener)
|
1999-11-24 06:03:41 +00:00
|
|
|
mScrollbarListener->PositionChanged(aPresContext, mCurPos, curpos);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-23 17:00:17 +00:00
|
|
|
mCurPos = curpos;
|
|
|
|
|
1999-10-20 00:46:21 +00:00
|
|
|
return NS_OK;
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
2003-03-24 05:29:45 +00:00
|
|
|
static void UpdateAttribute(nsIContent* aScrollbar, nscoord aNewPos, PRBool aNotify, PRBool aIsSmooth) {
|
|
|
|
nsAutoString str;
|
|
|
|
str.AppendInt(aNewPos);
|
|
|
|
|
|
|
|
if (aIsSmooth) {
|
|
|
|
aScrollbar->SetAttr(kNameSpaceID_None, nsXULAtoms::smooth, NS_LITERAL_STRING("true"), PR_FALSE);
|
|
|
|
}
|
|
|
|
aScrollbar->SetAttr(kNameSpaceID_None, nsXULAtoms::curpos, str, aNotify);
|
|
|
|
if (aIsSmooth) {
|
|
|
|
aScrollbar->UnsetAttr(kNameSpaceID_None, nsXULAtoms::smooth, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
void
|
2003-03-24 05:29:45 +00:00
|
|
|
nsSliderFrame::SetCurrentPosition(nsIContent* scrollbar, nsIFrame* aThumbFrame, nscoord newpos, PRBool aIsSmooth)
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
// get our current position and max position from our content node
|
|
|
|
PRInt32 maxpos = GetMaxPosition(scrollbar);
|
|
|
|
|
|
|
|
// get the new position and make sure it is in bounds
|
|
|
|
if (newpos > maxpos)
|
|
|
|
newpos = maxpos;
|
2001-07-15 00:05:20 +00:00
|
|
|
else if (newpos < 0)
|
1999-06-15 04:02:43 +00:00
|
|
|
newpos = 0;
|
|
|
|
|
2000-06-06 23:13:05 +00:00
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
|
|
|
nsCOMPtr<nsIScrollbarFrame> scrollbarFrame(do_QueryInterface(scrollbarBox));
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-10-07 00:49:08 +00:00
|
|
|
|
2000-06-06 23:13:05 +00:00
|
|
|
if (scrollbarFrame) {
|
|
|
|
// See if we have a mediator.
|
|
|
|
nsCOMPtr<nsIScrollbarMediator> mediator;
|
|
|
|
scrollbarFrame->GetScrollbarMediator(getter_AddRefs(mediator));
|
|
|
|
if (mediator) {
|
|
|
|
mediator->PositionChanged(GetCurrentPosition(scrollbar), newpos);
|
2003-03-24 05:29:45 +00:00
|
|
|
UpdateAttribute(scrollbar, newpos, PR_FALSE, aIsSmooth);
|
2003-09-14 01:25:04 +00:00
|
|
|
CurrentPositionChanged(GetPresContext());
|
2000-06-06 23:13:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-24 05:29:45 +00:00
|
|
|
UpdateAttribute(scrollbar, newpos, PR_TRUE, aIsSmooth);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2002-11-26 21:38:18 +00:00
|
|
|
#ifdef DEBUG_SLIDER
|
2002-12-31 12:50:10 +00:00
|
|
|
printf("Current Pos=%d\n",newpos);
|
2002-11-26 21:38:18 +00:00
|
|
|
#endif
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 04:44:41 +00:00
|
|
|
NS_IMETHODIMP nsSliderFrame::GetFrameForPoint(nsIPresContext* aPresContext,
|
2001-07-15 00:05:20 +00:00
|
|
|
const nsPoint& aPoint,
|
2000-03-22 02:43:08 +00:00
|
|
|
nsFramePaintLayer aWhichLayer,
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIFrame** aFrame)
|
2001-07-15 00:05:20 +00:00
|
|
|
{
|
2003-04-08 20:50:57 +00:00
|
|
|
// This is EVIL, we shouldn't be messing with GetFrameForPoint just to get
|
|
|
|
// thumb mouse drag events to arrive at the slider!
|
2003-09-14 01:25:04 +00:00
|
|
|
if (isDraggingThumb())
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
2000-03-22 02:43:08 +00:00
|
|
|
// XXX I assume it's better not to test for visibility here.
|
1999-06-15 04:02:43 +00:00
|
|
|
*aFrame = this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
if (NS_SUCCEEDED(nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aWhichLayer, aFrame)))
|
|
|
|
return NS_OK;
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-03-22 02:43:08 +00:00
|
|
|
// always return us (if visible)
|
2003-11-15 00:47:43 +00:00
|
|
|
if (mRect.Contains(aPoint) && GetStyleVisibility()->IsVisible()) {
|
2000-03-22 02:43:08 +00:00
|
|
|
*aFrame = this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSliderFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
nsresult r = nsBoxFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
AddListener();
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2000-04-26 04:00:29 +00:00
|
|
|
nsresult
|
|
|
|
nsSliderMediator::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2003-09-14 01:25:04 +00:00
|
|
|
// Only process the event if the thumb is not being dragged.
|
|
|
|
if (mSlider && !mSlider->isDraggingThumb())
|
2001-07-15 00:05:20 +00:00
|
|
|
return mSlider->MouseDown(aMouseEvent);
|
2003-09-14 01:25:04 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-26 04:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSliderMediator::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2003-09-14 01:25:04 +00:00
|
|
|
// Only process the event if the thumb is not being dragged.
|
|
|
|
if (mSlider && !mSlider->isDraggingThumb())
|
2001-07-15 00:05:20 +00:00
|
|
|
return mSlider->MouseUp(aMouseEvent);
|
2003-09-14 01:25:04 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-26 04:00:29 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
nsresult
|
|
|
|
nsSliderFrame::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
//printf("Begin dragging\n");
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
PRBool isHorizontal = IsHorizontal();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2000-04-26 04:00:29 +00:00
|
|
|
PRUint16 button = 0;
|
2003-11-24 23:52:49 +00:00
|
|
|
PRBool scrollToClick = PR_FALSE;
|
|
|
|
mouseEvent->GetShiftKey(&scrollToClick);
|
2000-04-26 04:00:29 +00:00
|
|
|
mouseEvent->GetButton(&button);
|
2003-11-24 23:52:49 +00:00
|
|
|
if (button != 0) {
|
2004-01-27 05:19:57 +00:00
|
|
|
if (button != 1 || !gMiddlePref)
|
2000-06-03 02:07:52 +00:00
|
|
|
return NS_OK;
|
2003-11-24 23:52:49 +00:00
|
|
|
scrollToClick = PR_TRUE;
|
|
|
|
}
|
2000-06-03 02:07:52 +00:00
|
|
|
|
2003-11-24 23:52:49 +00:00
|
|
|
// If shift click or middle button, first
|
|
|
|
// place the middle of the slider thumb under the click
|
|
|
|
if (scrollToClick) {
|
2000-06-03 02:07:52 +00:00
|
|
|
|
|
|
|
nscoord pos;
|
|
|
|
nscoord pospx;
|
|
|
|
|
|
|
|
// mouseEvent has click coordinates in pixels, convert to twips first
|
|
|
|
isHorizontal ? mouseEvent->GetClientX(&pospx) : mouseEvent->GetClientY(&pospx);
|
|
|
|
float p2t;
|
2003-09-14 01:25:04 +00:00
|
|
|
GetPresContext()->GetScaledPixelsToTwips(&p2t);
|
2000-06-03 02:07:52 +00:00
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
pos = pospx * onePixel;
|
|
|
|
|
|
|
|
// then get it into our coordinate system by subtracting our parents offsets.
|
|
|
|
nsIFrame* parent = this;
|
|
|
|
while(parent != nsnull) {
|
|
|
|
// if we hit a scrollable view make sure we take into account
|
|
|
|
// how much we are scrolled.
|
|
|
|
// XXX hack
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = parent->GetView();
|
2000-06-03 02:07:52 +00:00
|
|
|
if (view) {
|
2003-06-19 23:44:01 +00:00
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
nsresult result = CallQueryInterface(view, &scrollingView);
|
2000-06-03 02:07:52 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nscoord xoff = 0;
|
|
|
|
nscoord yoff = 0;
|
|
|
|
scrollingView->GetScrollPosition(xoff, yoff);
|
|
|
|
isHorizontal ? pos += xoff : pos += yoff;
|
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:00:29 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
pos -= (isHorizontal ? parent->GetPosition().x : parent->GetPosition().y);
|
|
|
|
parent = parent->GetParent();
|
2000-06-03 02:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now convert back into pixels
|
|
|
|
pospx = pos/onePixel;
|
|
|
|
|
|
|
|
// adjust so that the middle of the thumb is placed under the click
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2003-08-04 12:39:51 +00:00
|
|
|
nsSize thumbSize = thumbFrame->GetSize();
|
2000-06-03 02:07:52 +00:00
|
|
|
nscoord thumbLength = isHorizontal ? thumbSize.width : thumbSize.height;
|
|
|
|
thumbLength /= onePixel;
|
|
|
|
pospx -= (thumbLength/2);
|
|
|
|
|
|
|
|
// finally, convert to scrollbar's internal coordinate system
|
|
|
|
pospx = nscoord(pospx/mRatio);
|
|
|
|
|
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
|
|
|
nsCOMPtr<nsIContent> scrollbar;
|
2003-06-02 02:39:26 +00:00
|
|
|
scrollbar = GetContentOfBox(scrollbarBox);
|
2000-06-03 02:07:52 +00:00
|
|
|
|
|
|
|
// set it
|
2003-03-24 05:29:45 +00:00
|
|
|
SetCurrentPosition(scrollbar, thumbFrame, pospx, PR_FALSE);
|
2000-06-03 02:07:52 +00:00
|
|
|
}
|
2000-04-26 04:00:29 +00:00
|
|
|
|
2003-09-14 01:25:04 +00:00
|
|
|
DragThumb(PR_TRUE);
|
1999-06-15 04:02:43 +00:00
|
|
|
PRInt32 c = 0;
|
|
|
|
if (isHorizontal)
|
1999-11-03 07:11:45 +00:00
|
|
|
mouseEvent->GetClientX(&c);
|
1999-06-15 04:02:43 +00:00
|
|
|
else
|
1999-11-03 07:11:45 +00:00
|
|
|
mouseEvent->GetClientY(&c);
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
mDragStartPx = c;
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
|
|
|
|
|
|
|
if (isHorizontal)
|
2003-08-04 12:39:51 +00:00
|
|
|
mThumbStart = thumbFrame->GetPosition().x;
|
1999-06-15 04:02:43 +00:00
|
|
|
else
|
2003-08-04 12:39:51 +00:00
|
|
|
mThumbStart = thumbFrame->GetPosition().y;
|
2001-07-15 00:05:20 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
//printf("Pressed mDragStartPx=%d\n",mDragStartPx);
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSliderFrame::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
// printf("Finish dragging\n");
|
1999-08-19 22:16:23 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-09-14 01:25:04 +00:00
|
|
|
void
|
|
|
|
nsSliderFrame::DragThumb(PRBool aGrabMouseEvents)
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
|
|
|
// get its view
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = GetView();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
if (view) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIViewManager* viewMan = view->GetViewManager();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
if (viewMan) {
|
2003-08-04 12:39:51 +00:00
|
|
|
PRBool result;
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
if (aGrabMouseEvents) {
|
|
|
|
viewMan->GrabMouseEvents(view,result);
|
|
|
|
} else {
|
|
|
|
viewMan->GrabMouseEvents(nsnull,result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2003-09-14 01:25:04 +00:00
|
|
|
nsSliderFrame::isDraggingThumb()
|
1999-06-15 04:02:43 +00:00
|
|
|
{
|
|
|
|
// get its view
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = GetView();
|
2001-07-15 00:05:20 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
if (view) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIViewManager* viewMan = view->GetViewManager();
|
1999-06-15 04:02:43 +00:00
|
|
|
|
|
|
|
if (viewMan) {
|
|
|
|
nsIView* grabbingView;
|
|
|
|
viewMan->GetMouseEventGrabber(grabbingView);
|
|
|
|
if (grabbingView == view)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSliderFrame::AddListener()
|
|
|
|
{
|
2000-04-26 04:00:29 +00:00
|
|
|
if (!mMediator) {
|
|
|
|
mMediator = new nsSliderMediator(this);
|
|
|
|
NS_ADDREF(mMediator);
|
|
|
|
}
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2001-01-11 01:56:27 +00:00
|
|
|
if (thumbFrame) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIDOMEventReceiver>
|
|
|
|
receiver(do_QueryInterface(thumbFrame->GetContent()));
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
receiver->AddEventListenerByIID(mMediator, NS_GET_IID(nsIDOMMouseListener));
|
2001-01-11 01:56:27 +00:00
|
|
|
}
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSliderFrame::RemoveListener()
|
|
|
|
{
|
2000-04-26 04:00:29 +00:00
|
|
|
NS_ASSERTION(mMediator, "No listener was ever added!!");
|
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2001-12-17 22:51:39 +00:00
|
|
|
if (!thumbFrame)
|
|
|
|
return;
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIDOMEventReceiver>
|
|
|
|
receiver(do_QueryInterface(thumbFrame->GetContent()));
|
1999-06-15 04:02:43 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
receiver->RemoveEventListenerByIID(mMediator, NS_GET_IID(nsIDOMMouseListener));
|
1999-06-15 04:02:43 +00:00
|
|
|
}
|
1999-06-23 17:00:17 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
NS_IMETHODIMP
|
2001-07-15 00:05:20 +00:00
|
|
|
nsSliderFrame::HandlePress(nsIPresContext* aPresContext,
|
2002-11-23 05:20:05 +00:00
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
2003-11-24 23:52:49 +00:00
|
|
|
if (((nsMouseEvent *)aEvent)->isShift)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2002-11-23 05:20:05 +00:00
|
|
|
if (!thumbFrame) // display:none?
|
|
|
|
return NS_OK;
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
2002-11-23 05:20:05 +00:00
|
|
|
|
|
|
|
nscoord change = 1;
|
|
|
|
if (IsHorizontal() ? aEvent->point.x < thumbRect.x
|
|
|
|
: aEvent->point.y < thumbRect.y)
|
|
|
|
change = -1;
|
|
|
|
|
|
|
|
mChange = change;
|
2004-01-27 05:19:57 +00:00
|
|
|
mDestinationPoint = aEvent->point;
|
2002-11-23 05:20:05 +00:00
|
|
|
PageUpDown(thumbFrame, change);
|
|
|
|
|
|
|
|
nsRepeatService::GetInstance()->Start(mMediator);
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::HandleRelease(nsIPresContext* aPresContext,
|
1999-08-19 22:16:23 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
|
|
|
nsRepeatService::GetInstance()->Stop();
|
|
|
|
|
2004-01-27 05:19:57 +00:00
|
|
|
mChange = 0;
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-29 10:51:15 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsSliderFrame::Destroy(nsIPresContext* aPresContext)
|
1999-08-29 10:51:15 +00:00
|
|
|
{
|
2000-04-26 04:00:29 +00:00
|
|
|
// tell our mediator if we have one we are gone.
|
|
|
|
if (mMediator) {
|
|
|
|
mMediator->SetSlider(nsnull);
|
|
|
|
NS_RELEASE(mMediator);
|
|
|
|
mMediator = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-12-13 23:33:17 +00:00
|
|
|
// call base class Destroy()
|
2000-03-31 07:02:06 +00:00
|
|
|
return nsBoxFrame::Destroy(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize)
|
|
|
|
{
|
|
|
|
EnsureOrient();
|
|
|
|
return nsBoxFrame::GetPrefSize(aState, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::GetMinSize(nsBoxLayoutState& aState, nsSize& aSize)
|
|
|
|
{
|
|
|
|
EnsureOrient();
|
|
|
|
|
|
|
|
// our min size is just our borders and padding
|
|
|
|
return nsBox::GetMinSize(aState, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSliderFrame::GetMaxSize(nsBoxLayoutState& aState, nsSize& aSize)
|
|
|
|
{
|
|
|
|
EnsureOrient();
|
|
|
|
return nsBoxFrame::GetMaxSize(aState, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSliderFrame::EnsureOrient()
|
|
|
|
{
|
|
|
|
nsIBox* scrollbarBox = GetScrollbar();
|
|
|
|
|
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
scrollbarBox->GetFrame(&frame);
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
PRBool isHorizontal = frame->GetStateBits() & NS_STATE_IS_HORIZONTAL;
|
2000-03-31 07:02:06 +00:00
|
|
|
if (isHorizontal)
|
|
|
|
mState |= NS_STATE_IS_HORIZONTAL;
|
|
|
|
else
|
|
|
|
mState &= ~NS_STATE_IS_HORIZONTAL;
|
1999-08-29 10:51:15 +00:00
|
|
|
}
|
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2001-07-15 00:05:20 +00:00
|
|
|
void
|
1999-06-23 17:00:17 +00:00
|
|
|
nsSliderFrame::SetScrollbarListener(nsIScrollbarListener* aListener)
|
|
|
|
{
|
|
|
|
// Don't addref/release this, since it's actually a frame.
|
|
|
|
mScrollbarListener = aListener;
|
|
|
|
}
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_IMETHODIMP nsSliderMediator::Notify(nsITimer *timer)
|
2001-07-15 00:05:20 +00:00
|
|
|
{
|
2000-04-26 04:00:29 +00:00
|
|
|
if (mSlider)
|
2001-07-15 00:05:20 +00:00
|
|
|
mSlider->Notify(timer);
|
2002-09-07 05:38:16 +00:00
|
|
|
return NS_OK;
|
2000-04-26 04:00:29 +00:00
|
|
|
}
|
|
|
|
|
2000-01-21 21:56:09 +00:00
|
|
|
NS_IMETHODIMP_(void) nsSliderFrame::Notify(nsITimer *timer)
|
2001-07-15 00:05:20 +00:00
|
|
|
{
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
PRBool stop = PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* thumbFrame = mFrames.FirstChild();
|
2003-08-04 12:39:51 +00:00
|
|
|
nsRect thumbRect = thumbFrame->GetRect();
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
PRBool isHorizontal = IsHorizontal();
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
|
2004-01-27 05:19:57 +00:00
|
|
|
// See if the thumb has moved past our destination point.
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
// if it has we want to stop.
|
|
|
|
if (isHorizontal) {
|
|
|
|
if (mChange < 0) {
|
2004-01-27 05:19:57 +00:00
|
|
|
if (thumbRect.x < mDestinationPoint.x)
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
stop = PR_TRUE;
|
|
|
|
} else {
|
2004-01-27 05:19:57 +00:00
|
|
|
if (thumbRect.x + thumbRect.width > mDestinationPoint.x)
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
stop = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mChange < 0) {
|
2004-01-27 05:19:57 +00:00
|
|
|
if (thumbRect.y < mDestinationPoint.y)
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
stop = PR_TRUE;
|
|
|
|
} else {
|
2004-01-27 05:19:57 +00:00
|
|
|
if (thumbRect.y + thumbRect.height > mDestinationPoint.y)
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
stop = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stop) {
|
|
|
|
nsRepeatService::GetInstance()->Stop();
|
|
|
|
} else {
|
|
|
|
PageUpDown(thumbFrame, mChange);
|
|
|
|
}
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2000-04-26 04:00:29 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSliderMediator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2003-09-07 22:37:27 +00:00
|
|
|
NS_IMPL_ADDREF(nsSliderMediator)
|
|
|
|
NS_IMPL_RELEASE(nsSliderMediator)
|
2000-03-31 07:02:06 +00:00
|
|
|
|