gecko-dev/layout/xul/nsSplitterFrame.cpp
Robert O'Callahan e96ed2b16c Bug 945091. Part 3: Flatten layout/xul/base/* into layout/xul. r=glandium
--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
2013-12-04 14:06:16 +13:00

1054 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 "nsSplitterFrame.h"
#include "nsGkAtoms.h"
#include "nsIDOMElement.h"
#include "nsIDOMXULElement.h"
#include "nsPresContext.h"
#include "nsRenderingContext.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
#include "nsScrollbarButtonFrame.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMMouseEvent.h"
#include "nsIPresShell.h"
#include "nsFrameList.h"
#include "nsHTMLParts.h"
#include "nsStyleContext.h"
#include "nsBoxLayoutState.h"
#include "nsIServiceManager.h"
#include "nsContainerFrame.h"
#include "nsAutoPtr.h"
#include "nsContentCID.h"
#include "nsStyleSet.h"
#include "nsLayoutUtils.h"
#include "nsDisplayList.h"
#include "nsContentUtils.h"
#include "mozilla/dom/Element.h"
#include "mozilla/MouseEvents.h"
using namespace mozilla;
class nsSplitterInfo {
public:
nscoord min;
nscoord max;
nscoord current;
nscoord changed;
nsCOMPtr<nsIContent> childElem;
int32_t flex;
int32_t index;
};
class nsSplitterFrameInner : public nsIDOMEventListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTLISTENER
nsSplitterFrameInner(nsSplitterFrame* aSplitter)
{
mOuter = aSplitter;
mPressed = false;
}
virtual ~nsSplitterFrameInner();
void Disconnect() { mOuter = nullptr; }
nsresult MouseDown(nsIDOMEvent* aMouseEvent);
nsresult MouseUp(nsIDOMEvent* aMouseEvent);
nsresult MouseMove(nsIDOMEvent* aMouseEvent);
void MouseDrag(nsPresContext* aPresContext, WidgetGUIEvent* aEvent);
void MouseUp(nsPresContext* aPresContext, WidgetGUIEvent* aEvent);
void AdjustChildren(nsPresContext* aPresContext);
void AdjustChildren(nsPresContext* aPresContext, nsSplitterInfo* aChildInfos, int32_t aCount, bool aIsHorizontal);
void AddRemoveSpace(nscoord aDiff,
nsSplitterInfo* aChildInfos,
int32_t aCount,
int32_t& aSpaceLeft);
void ResizeChildTo(nsPresContext* aPresContext,
nscoord& aDiff,
nsSplitterInfo* aChildrenBeforeInfos,
nsSplitterInfo* aChildrenAfterInfos,
int32_t aChildrenBeforeCount,
int32_t aChildrenAfterCount,
bool aBounded);
void UpdateState();
void AddListener(nsPresContext* aPresContext);
void RemoveListener();
enum ResizeType { Closest, Farthest, Flex, Grow };
enum State { Open, CollapsedBefore, CollapsedAfter, Dragging };
enum CollapseDirection { Before, After };
ResizeType GetResizeBefore();
ResizeType GetResizeAfter();
State GetState();
void Reverse(nsSplitterInfo*& aIndexes, int32_t aCount);
bool SupportsCollapseDirection(CollapseDirection aDirection);
void EnsureOrient();
void SetPreferredSize(nsBoxLayoutState& aState, nsIFrame* aChildBox, nscoord aOnePixel, bool aIsHorizontal, nscoord* aSize);
nsSplitterFrame* mOuter;
bool mDidDrag;
nscoord mDragStart;
nscoord mCurrentPos;
nsIFrame* mParentBox;
bool mPressed;
nsSplitterInfo* mChildInfosBefore;
nsSplitterInfo* mChildInfosAfter;
int32_t mChildInfosBeforeCount;
int32_t mChildInfosAfterCount;
State mState;
nscoord mSplitterPos;
bool mDragging;
};
NS_IMPL_ISUPPORTS1(nsSplitterFrameInner, nsIDOMEventListener)
nsSplitterFrameInner::ResizeType
nsSplitterFrameInner::GetResizeBefore()
{
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::farthest, &nsGkAtoms::flex, nullptr};
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::resizebefore,
strings, eCaseMatters)) {
case 0: return Farthest;
case 1: return Flex;
}
return Closest;
}
nsSplitterFrameInner::~nsSplitterFrameInner()
{
delete[] mChildInfosBefore;
delete[] mChildInfosAfter;
}
nsSplitterFrameInner::ResizeType
nsSplitterFrameInner::GetResizeAfter()
{
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::farthest, &nsGkAtoms::flex, &nsGkAtoms::grow, nullptr};
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::resizeafter,
strings, eCaseMatters)) {
case 0: return Farthest;
case 1: return Flex;
case 2: return Grow;
}
return Closest;
}
nsSplitterFrameInner::State
nsSplitterFrameInner::GetState()
{
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::dragging, &nsGkAtoms::collapsed, nullptr};
static nsIContent::AttrValuesArray strings_substate[] =
{&nsGkAtoms::before, &nsGkAtoms::after, nullptr};
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::state,
strings, eCaseMatters)) {
case 0: return Dragging;
case 1:
switch (mOuter->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::substate,
strings_substate,
eCaseMatters)) {
case 0: return CollapsedBefore;
case 1: return CollapsedAfter;
default:
if (SupportsCollapseDirection(After))
return CollapsedAfter;
return CollapsedBefore;
}
}
return Open;
}
//
// NS_NewSplitterFrame
//
// Creates a new Toolbar frame and returns it
//
nsIFrame*
NS_NewSplitterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
{
return new (aPresShell) nsSplitterFrame(aPresShell, aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsSplitterFrame)
nsSplitterFrame::nsSplitterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
: nsBoxFrame(aPresShell, aContext),
mInner(0)
{
}
void
nsSplitterFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
if (mInner) {
mInner->RemoveListener();
mInner->Disconnect();
mInner->Release();
mInner = nullptr;
}
nsBoxFrame::DestroyFrom(aDestructRoot);
}
NS_IMETHODIMP
nsSplitterFrame::GetCursor(const nsPoint& aPoint,
nsIFrame::Cursor& aCursor)
{
return nsBoxFrame::GetCursor(aPoint, aCursor);
/*
if (IsHorizontal())
aCursor = NS_STYLE_CURSOR_N_RESIZE;
else
aCursor = NS_STYLE_CURSOR_W_RESIZE;
return NS_OK;
*/
}
NS_IMETHODIMP
nsSplitterFrame::AttributeChanged(int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType)
{
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
aModType);
// if the alignment changed. Let the grippy know
if (aAttribute == nsGkAtoms::align) {
// tell the slider its attribute changed so it can
// update itself
nsIFrame* grippy = nullptr;
nsScrollbarButtonFrame::GetChildWithTag(PresContext(), nsGkAtoms::grippy, this, grippy);
if (grippy)
grippy->AttributeChanged(aNameSpaceID, aAttribute, aModType);
} else if (aAttribute == nsGkAtoms::state) {
mInner->UpdateState();
}
return rv;
}
/**
* Initialize us. If we are in a box get our alignment so we know what direction we are
*/
void
nsSplitterFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
MOZ_ASSERT(!mInner);
mInner = new nsSplitterFrameInner(this);
mInner->AddRef();
mInner->mChildInfosAfter = nullptr;
mInner->mChildInfosBefore = nullptr;
mInner->mState = nsSplitterFrameInner::Open;
mInner->mDragging = false;
// determine orientation of parent, and if vertical, set orient to vertical
// on splitter content, then re-resolve style
// XXXbz this is pretty messed up, since this can change whether we should
// have a frame at all. This really needs a better solution.
if (aParent && aParent->IsBoxFrame()) {
if (!aParent->IsHorizontal()) {
if (!nsContentUtils::HasNonEmptyAttr(aContent, kNameSpaceID_None,
nsGkAtoms::orient)) {
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient,
NS_LITERAL_STRING("vertical"), false);
nsStyleContext* parentStyleContext = StyleContext()->GetParent();
nsRefPtr<nsStyleContext> newContext = PresContext()->StyleSet()->
ResolveStyleFor(aContent->AsElement(), parentStyleContext);
SetStyleContextWithoutNotification(newContext);
}
}
}
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
mInner->mState = nsSplitterFrameInner::Open;
mInner->AddListener(PresContext());
mInner->mParentBox = nullptr;
}
NS_IMETHODIMP
nsSplitterFrame::DoLayout(nsBoxLayoutState& aState)
{
if (GetStateBits() & NS_FRAME_FIRST_REFLOW)
{
mInner->mParentBox = GetParentBox();
mInner->UpdateState();
}
return nsBoxFrame::DoLayout(aState);
}
void
nsSplitterFrame::GetInitialOrientation(bool& aIsHorizontal)
{
nsIFrame* box = GetParentBox();
if (box) {
aIsHorizontal = !box->IsHorizontal();
}
else
nsBoxFrame::GetInitialOrientation(aIsHorizontal);
}
NS_IMETHODIMP
nsSplitterFrame::HandlePress(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
return NS_OK;
}
NS_IMETHODIMP
nsSplitterFrame::HandleMultiplePress(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus,
bool aControlHeld)
{
return NS_OK;
}
NS_IMETHODIMP
nsSplitterFrame::HandleDrag(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
return NS_OK;
}
NS_IMETHODIMP
nsSplitterFrame::HandleRelease(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
return NS_OK;
}
void
nsSplitterFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
{
nsBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
// if the mouse is captured always return us as the frame.
if (mInner->mDragging)
{
// XXX It's probably better not to check visibility here, right?
aLists.Outlines()->AppendNewToTop(new (aBuilder)
nsDisplayEventReceiver(aBuilder, this));
return;
}
}
NS_IMETHODIMP
nsSplitterFrame::HandleEvent(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
return NS_OK;
}
nsWeakFrame weakFrame(this);
nsRefPtr<nsSplitterFrameInner> kungFuDeathGrip(mInner);
switch (aEvent->message) {
case NS_MOUSE_MOVE:
mInner->MouseDrag(aPresContext, aEvent);
break;
case NS_MOUSE_BUTTON_UP:
if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
mInner->MouseUp(aPresContext, aEvent);
}
break;
}
NS_ENSURE_STATE(weakFrame.IsAlive());
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
void
nsSplitterFrameInner::MouseUp(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent)
{
if (mDragging && mOuter) {
AdjustChildren(aPresContext);
AddListener(aPresContext);
nsIPresShell::SetCapturingContent(nullptr, 0); // XXXndeakin is this needed?
mDragging = false;
State newState = GetState();
// if the state is dragging then make it Open.
if (newState == Dragging)
mOuter->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::state, EmptyString(), true);
mPressed = false;
// if we dragged then fire a command event.
if (mDidDrag) {
nsCOMPtr<nsIDOMXULElement> element = do_QueryInterface(mOuter->GetContent());
element->DoCommand();
}
//printf("MouseUp\n");
}
delete[] mChildInfosBefore;
delete[] mChildInfosAfter;
mChildInfosBefore = nullptr;
mChildInfosAfter = nullptr;
mChildInfosBeforeCount = 0;
mChildInfosAfterCount = 0;
}
void
nsSplitterFrameInner::MouseDrag(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent)
{
if (mDragging && mOuter) {
//printf("Dragging\n");
bool isHorizontal = !mOuter->IsHorizontal();
// convert coord to pixels
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
mParentBox);
nscoord pos = isHorizontal ? pt.x : pt.y;
// mDragStart is in frame coordinates
nscoord start = mDragStart;
// take our current position and subtract the start location
pos -= start;
//printf("Diff=%d\n", pos);
ResizeType resizeAfter = GetResizeAfter();
bool bounded;
if (resizeAfter == nsSplitterFrameInner::Grow)
bounded = false;
else
bounded = true;
int i;
for (i=0; i < mChildInfosBeforeCount; i++)
mChildInfosBefore[i].changed = mChildInfosBefore[i].current;
for (i=0; i < mChildInfosAfterCount; i++)
mChildInfosAfter[i].changed = mChildInfosAfter[i].current;
nscoord oldPos = pos;
ResizeChildTo(aPresContext, pos, mChildInfosBefore, mChildInfosAfter, mChildInfosBeforeCount, mChildInfosAfterCount, bounded);
State currentState = GetState();
bool supportsBefore = SupportsCollapseDirection(Before);
bool supportsAfter = SupportsCollapseDirection(After);
const bool isRTL = mOuter->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
bool pastEnd = oldPos > 0 && oldPos > pos;
bool pastBegin = oldPos < 0 && oldPos < pos;
if (isRTL) {
// Swap the boundary checks in RTL mode
bool tmp = pastEnd;
pastEnd = pastBegin;
pastBegin = tmp;
}
const bool isCollapsedBefore = pastBegin && supportsBefore;
const bool isCollapsedAfter = pastEnd && supportsAfter;
// if we are in a collapsed position
if (isCollapsedBefore || isCollapsedAfter)
{
// and we are not collapsed then collapse
if (currentState == Dragging) {
if (pastEnd)
{
//printf("Collapse right\n");
if (supportsAfter)
{
nsCOMPtr<nsIContent> outer = mOuter->mContent;
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::substate,
NS_LITERAL_STRING("after"),
true);
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::state,
NS_LITERAL_STRING("collapsed"),
true);
}
} else if (pastBegin)
{
//printf("Collapse left\n");
if (supportsBefore)
{
nsCOMPtr<nsIContent> outer = mOuter->mContent;
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::substate,
NS_LITERAL_STRING("before"),
true);
outer->SetAttr(kNameSpaceID_None, nsGkAtoms::state,
NS_LITERAL_STRING("collapsed"),
true);
}
}
}
} else {
// if we are not in a collapsed position and we are not dragging make sure
// we are dragging.
if (currentState != Dragging)
mOuter->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::state, NS_LITERAL_STRING("dragging"), true);
AdjustChildren(aPresContext);
}
mDidDrag = true;
}
}
void
nsSplitterFrameInner::AddListener(nsPresContext* aPresContext)
{
mOuter->GetContent()->
AddEventListener(NS_LITERAL_STRING("mouseup"), this, false, false);
mOuter->GetContent()->
AddEventListener(NS_LITERAL_STRING("mousedown"), this, false, false);
mOuter->GetContent()->
AddEventListener(NS_LITERAL_STRING("mousemove"), this, false, false);
mOuter->GetContent()->
AddEventListener(NS_LITERAL_STRING("mouseout"), this, false, false);
}
void
nsSplitterFrameInner::RemoveListener()
{
ENSURE_TRUE(mOuter);
mOuter->GetContent()->
RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, false);
mOuter->GetContent()->
RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, false);
mOuter->GetContent()->
RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, false);
mOuter->GetContent()->
RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, false);
}
nsresult
nsSplitterFrameInner::HandleEvent(nsIDOMEvent* aEvent)
{
nsAutoString eventType;
aEvent->GetType(eventType);
if (eventType.EqualsLiteral("mouseup"))
return MouseUp(aEvent);
if (eventType.EqualsLiteral("mousedown"))
return MouseDown(aEvent);
if (eventType.EqualsLiteral("mousemove") ||
eventType.EqualsLiteral("mouseout"))
return MouseMove(aEvent);
NS_ABORT();
return NS_OK;
}
nsresult
nsSplitterFrameInner::MouseUp(nsIDOMEvent* aMouseEvent)
{
NS_ENSURE_TRUE(mOuter, NS_OK);
mPressed = false;
nsIPresShell::SetCapturingContent(nullptr, 0);
return NS_OK;
}
nsresult
nsSplitterFrameInner::MouseDown(nsIDOMEvent* aMouseEvent)
{
NS_ENSURE_TRUE(mOuter, NS_OK);
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
if (!mouseEvent)
return NS_OK;
uint16_t button = 0;
mouseEvent->GetButton(&button);
// only if left button
if (button != 0)
return NS_OK;
if (mOuter->GetContent()->
AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
nsGkAtoms::_true, eCaseMatters))
return NS_OK;
mParentBox = mOuter->GetParentBox();
if (!mParentBox)
return NS_OK;
// get our index
nsPresContext* outerPresContext = mOuter->PresContext();
const nsFrameList& siblingList(mParentBox->PrincipalChildList());
int32_t childIndex = siblingList.IndexOf(mOuter);
// if it's 0 (or not found) then stop right here.
// It might be not found if we're not in the parent's primary frame list.
if (childIndex <= 0)
return NS_OK;
int32_t childCount = siblingList.GetLength();
// if it's the last index then we need to allow for resizeafter="grow"
if (childIndex == childCount - 1 && GetResizeAfter() != Grow)
return NS_OK;
nsRefPtr<nsRenderingContext> rc =
outerPresContext->PresShell()->GetReferenceRenderingContext();
NS_ENSURE_TRUE(rc, NS_ERROR_FAILURE);
nsBoxLayoutState state(outerPresContext, rc);
mCurrentPos = 0;
mPressed = true;
mDidDrag = false;
EnsureOrient();
bool isHorizontal = !mOuter->IsHorizontal();
ResizeType resizeBefore = GetResizeBefore();
ResizeType resizeAfter = GetResizeAfter();
delete[] mChildInfosBefore;
delete[] mChildInfosAfter;
mChildInfosBefore = new nsSplitterInfo[childCount];
mChildInfosAfter = new nsSplitterInfo[childCount];
// create info 2 lists. One of the children before us and one after.
int32_t count = 0;
mChildInfosBeforeCount = 0;
mChildInfosAfterCount = 0;
nsIFrame* childBox = mParentBox->GetChildBox();
while (nullptr != childBox)
{
nsIContent* content = childBox->GetContent();
nsIDocument* doc = content->OwnerDoc();
int32_t dummy;
nsIAtom* atom = doc->BindingManager()->ResolveTag(content, &dummy);
// skip over any splitters
if (atom != nsGkAtoms::splitter) {
nsSize prefSize = childBox->GetPrefSize(state);
nsSize minSize = childBox->GetMinSize(state);
nsSize maxSize = nsBox::BoundsCheckMinMax(minSize, childBox->GetMaxSize(state));
prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize);
mOuter->AddMargin(childBox, minSize);
mOuter->AddMargin(childBox, prefSize);
mOuter->AddMargin(childBox, maxSize);
nscoord flex = childBox->GetFlex(state);
nsMargin margin(0,0,0,0);
childBox->GetMargin(margin);
nsRect r(childBox->GetRect());
r.Inflate(margin);
// We need to check for hidden attribute too, since treecols with
// the hidden="true" attribute are not really hidden, just collapsed
if (!content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::fixed,
nsGkAtoms::_true, eCaseMatters) &&
!content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
nsGkAtoms::_true, eCaseMatters)) {
if (count < childIndex && (resizeBefore != Flex || flex > 0)) {
mChildInfosBefore[mChildInfosBeforeCount].childElem = content;
mChildInfosBefore[mChildInfosBeforeCount].min = isHorizontal ? minSize.width : minSize.height;
mChildInfosBefore[mChildInfosBeforeCount].max = isHorizontal ? maxSize.width : maxSize.height;
mChildInfosBefore[mChildInfosBeforeCount].current = isHorizontal ? r.width : r.height;
mChildInfosBefore[mChildInfosBeforeCount].flex = flex;
mChildInfosBefore[mChildInfosBeforeCount].index = count;
mChildInfosBefore[mChildInfosBeforeCount].changed = mChildInfosBefore[mChildInfosBeforeCount].current;
mChildInfosBeforeCount++;
} else if (count > childIndex && (resizeAfter != Flex || flex > 0)) {
mChildInfosAfter[mChildInfosAfterCount].childElem = content;
mChildInfosAfter[mChildInfosAfterCount].min = isHorizontal ? minSize.width : minSize.height;
mChildInfosAfter[mChildInfosAfterCount].max = isHorizontal ? maxSize.width : maxSize.height;
mChildInfosAfter[mChildInfosAfterCount].current = isHorizontal ? r.width : r.height;
mChildInfosAfter[mChildInfosAfterCount].flex = flex;
mChildInfosAfter[mChildInfosAfterCount].index = count;
mChildInfosAfter[mChildInfosAfterCount].changed = mChildInfosAfter[mChildInfosAfterCount].current;
mChildInfosAfterCount++;
}
}
}
childBox = childBox->GetNextBox();
count++;
}
if (!mParentBox->IsNormalDirection()) {
// The before array is really the after array, and the order needs to be reversed.
// First reverse both arrays.
Reverse(mChildInfosBefore, mChildInfosBeforeCount);
Reverse(mChildInfosAfter, mChildInfosAfterCount);
// Now swap the two arrays.
nscoord newAfterCount = mChildInfosBeforeCount;
mChildInfosBeforeCount = mChildInfosAfterCount;
mChildInfosAfterCount = newAfterCount;
nsSplitterInfo* temp = mChildInfosAfter;
mChildInfosAfter = mChildInfosBefore;
mChildInfosBefore = temp;
}
// if resizebefore is not Farthest, reverse the list because the first child
// in the list is the farthest, and we want the first child to be the closest.
if (resizeBefore != Farthest)
Reverse(mChildInfosBefore, mChildInfosBeforeCount);
// if the resizeafter is the Farthest we must reverse the list because the first child in the list
// is the closest we want the first child to be the Farthest.
if (resizeAfter == Farthest)
Reverse(mChildInfosAfter, mChildInfosAfterCount);
// grow only applys to the children after. If grow is set then no space should be taken out of any children after
// us. To do this we just set the size of that list to be 0.
if (resizeAfter == Grow)
mChildInfosAfterCount = 0;
int32_t c;
nsPoint pt = nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(mouseEvent,
mParentBox);
if (isHorizontal) {
c = pt.x;
mSplitterPos = mOuter->mRect.x;
} else {
c = pt.y;
mSplitterPos = mOuter->mRect.y;
}
mDragStart = c;
//printf("Pressed mDragStart=%d\n",mDragStart);
nsIPresShell::SetCapturingContent(mOuter->GetContent(), CAPTURE_IGNOREALLOWED);
return NS_OK;
}
nsresult
nsSplitterFrameInner::MouseMove(nsIDOMEvent* aMouseEvent)
{
NS_ENSURE_TRUE(mOuter, NS_OK);
if (!mPressed)
return NS_OK;
if (mDragging)
return NS_OK;
nsCOMPtr<nsIDOMEventListener> kungfuDeathGrip(this);
mOuter->mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::state,
NS_LITERAL_STRING("dragging"), true);
RemoveListener();
mDragging = true;
return NS_OK;
}
void
nsSplitterFrameInner::Reverse(nsSplitterInfo*& aChildInfos, int32_t aCount)
{
nsSplitterInfo* infos = new nsSplitterInfo[aCount];
for (int i=0; i < aCount; i++)
infos[i] = aChildInfos[aCount - 1 - i];
delete[] aChildInfos;
aChildInfos = infos;
}
bool
nsSplitterFrameInner::SupportsCollapseDirection
(
nsSplitterFrameInner::CollapseDirection aDirection
)
{
static nsIContent::AttrValuesArray strings[] =
{&nsGkAtoms::before, &nsGkAtoms::after, &nsGkAtoms::both, nullptr};
switch (mOuter->mContent->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::collapse,
strings, eCaseMatters)) {
case 0:
return (aDirection == Before);
case 1:
return (aDirection == After);
case 2:
return true;
}
return false;
}
void
nsSplitterFrameInner::UpdateState()
{
// State Transitions:
// Open -> Dragging
// Open -> CollapsedBefore
// Open -> CollapsedAfter
// CollapsedBefore -> Open
// CollapsedBefore -> Dragging
// CollapsedAfter -> Open
// CollapsedAfter -> Dragging
// Dragging -> Open
// Dragging -> CollapsedBefore (auto collapse)
// Dragging -> CollapsedAfter (auto collapse)
State newState = GetState();
if (newState == mState) {
// No change.
return;
}
if ((SupportsCollapseDirection(Before) || SupportsCollapseDirection(After)) &&
mOuter->GetParent()->IsBoxFrame()) {
// Find the splitter's immediate sibling.
nsIFrame* splitterSibling;
if (newState == CollapsedBefore || mState == CollapsedBefore) {
splitterSibling = mOuter->GetPrevSibling();
} else {
splitterSibling = mOuter->GetNextSibling();
}
if (splitterSibling) {
nsCOMPtr<nsIContent> sibling = splitterSibling->GetContent();
if (sibling) {
if (mState == CollapsedBefore || mState == CollapsedAfter) {
// CollapsedBefore -> Open
// CollapsedBefore -> Dragging
// CollapsedAfter -> Open
// CollapsedAfter -> Dragging
nsContentUtils::AddScriptRunner(
new nsUnsetAttrRunnable(sibling, nsGkAtoms::collapsed));
} else if ((mState == Open || mState == Dragging)
&& (newState == CollapsedBefore ||
newState == CollapsedAfter)) {
// Open -> CollapsedBefore / CollapsedAfter
// Dragging -> CollapsedBefore / CollapsedAfter
nsContentUtils::AddScriptRunner(
new nsSetAttrRunnable(sibling, nsGkAtoms::collapsed,
NS_LITERAL_STRING("true")));
}
}
}
}
mState = newState;
}
void
nsSplitterFrameInner::EnsureOrient()
{
bool isHorizontal = !(mParentBox->GetStateBits() & NS_STATE_IS_HORIZONTAL);
if (isHorizontal)
mOuter->mState |= NS_STATE_IS_HORIZONTAL;
else
mOuter->mState &= ~NS_STATE_IS_HORIZONTAL;
}
void
nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext)
{
EnsureOrient();
bool isHorizontal = !mOuter->IsHorizontal();
AdjustChildren(aPresContext, mChildInfosBefore, mChildInfosBeforeCount, isHorizontal);
AdjustChildren(aPresContext, mChildInfosAfter, mChildInfosAfterCount, isHorizontal);
}
static nsIFrame* GetChildBoxForContent(nsIFrame* aParentBox, nsIContent* aContent)
{
nsIFrame* childBox = aParentBox->GetChildBox();
while (nullptr != childBox) {
if (childBox->GetContent() == aContent) {
return childBox;
}
childBox = childBox->GetNextBox();
}
return nullptr;
}
void
nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext, nsSplitterInfo* aChildInfos, int32_t aCount, bool aIsHorizontal)
{
///printf("------- AdjustChildren------\n");
nsBoxLayoutState state(aPresContext);
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
// first set all the widths.
nsIFrame* child = mOuter->GetChildBox();
while(child)
{
SetPreferredSize(state, child, onePixel, aIsHorizontal, nullptr);
child = child->GetNextBox();
}
// now set our changed widths.
for (int i=0; i < aCount; i++)
{
nscoord pref = aChildInfos[i].changed;
nsIFrame* childBox = GetChildBoxForContent(mParentBox, aChildInfos[i].childElem);
if (childBox) {
SetPreferredSize(state, childBox, onePixel, aIsHorizontal, &pref);
}
}
}
void
nsSplitterFrameInner::SetPreferredSize(nsBoxLayoutState& aState, nsIFrame* aChildBox, nscoord aOnePixel, bool aIsHorizontal, nscoord* aSize)
{
nsRect rect(aChildBox->GetRect());
nscoord pref = 0;
if (!aSize)
{
if (aIsHorizontal)
pref = rect.width;
else
pref = rect.height;
} else {
pref = *aSize;
}
nsMargin margin(0,0,0,0);
aChildBox->GetMargin(margin);
nsCOMPtr<nsIAtom> attribute;
if (aIsHorizontal) {
pref -= (margin.left + margin.right);
attribute = nsGkAtoms::width;
} else {
pref -= (margin.top + margin.bottom);
attribute = nsGkAtoms::height;
}
nsIContent* content = aChildBox->GetContent();
// set its preferred size.
nsAutoString prefValue;
prefValue.AppendInt(pref/aOnePixel);
if (content->AttrValueIs(kNameSpaceID_None, attribute,
prefValue, eCaseMatters))
return;
nsWeakFrame weakBox(aChildBox);
content->SetAttr(kNameSpaceID_None, attribute, prefValue, true);
ENSURE_TRUE(weakBox.IsAlive());
aState.PresShell()->FrameNeedsReflow(aChildBox, nsIPresShell::eStyleChange,
NS_FRAME_IS_DIRTY);
}
void
nsSplitterFrameInner::AddRemoveSpace(nscoord aDiff,
nsSplitterInfo* aChildInfos,
int32_t aCount,
int32_t& aSpaceLeft)
{
aSpaceLeft = 0;
for (int i=0; i < aCount; i++) {
nscoord min = aChildInfos[i].min;
nscoord max = aChildInfos[i].max;
nscoord& c = aChildInfos[i].changed;
// figure our how much space to add or remove
if (c + aDiff < min) {
aDiff += (c - min);
c = min;
} else if (c + aDiff > max) {
aDiff -= (max - c);
c = max;
} else {
c += aDiff;
aDiff = 0;
}
// there is not space left? We are done
if (aDiff == 0)
break;
}
aSpaceLeft = aDiff;
}
/**
* Ok if we want to resize a child we will know the actual size in pixels we want it to be.
* This is not the preferred size. But they only way we can change a child is my manipulating its
* preferred size. So give the actual pixel size this return method will return figure out the preferred
* size and set it.
*/
void
nsSplitterFrameInner::ResizeChildTo(nsPresContext* aPresContext,
nscoord& aDiff,
nsSplitterInfo* aChildrenBeforeInfos,
nsSplitterInfo* aChildrenAfterInfos,
int32_t aChildrenBeforeCount,
int32_t aChildrenAfterCount,
bool aBounded)
{
nscoord spaceLeft;
AddRemoveSpace(aDiff, aChildrenBeforeInfos,aChildrenBeforeCount,spaceLeft);
// if there is any space left over remove it from the dif we were originally given
aDiff -= spaceLeft;
AddRemoveSpace(-aDiff, aChildrenAfterInfos,aChildrenAfterCount,spaceLeft);
if (spaceLeft != 0) {
if (aBounded) {
aDiff += spaceLeft;
AddRemoveSpace(spaceLeft, aChildrenBeforeInfos,aChildrenBeforeCount,spaceLeft);
} else {
spaceLeft = 0;
}
}
}