1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/xul/nsScrollbarFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// 1.10 +// Eric Vaughan 1.11 +// Netscape Communications 1.12 +// 1.13 +// See documentation in associated header file 1.14 +// 1.15 + 1.16 +#include "nsScrollbarFrame.h" 1.17 +#include "nsScrollbarButtonFrame.h" 1.18 +#include "nsGkAtoms.h" 1.19 +#include "nsIScrollableFrame.h" 1.20 +#include "nsIScrollbarMediator.h" 1.21 +#include "mozilla/LookAndFeel.h" 1.22 +#include "nsThemeConstants.h" 1.23 +#include "nsRenderingContext.h" 1.24 +#include "nsIContent.h" 1.25 + 1.26 +using namespace mozilla; 1.27 + 1.28 +// 1.29 +// NS_NewScrollbarFrame 1.30 +// 1.31 +// Creates a new scrollbar frame and returns it 1.32 +// 1.33 +nsIFrame* 1.34 +NS_NewScrollbarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext) 1.35 +{ 1.36 + return new (aPresShell) nsScrollbarFrame (aPresShell, aContext); 1.37 +} 1.38 + 1.39 +NS_IMPL_FRAMEARENA_HELPERS(nsScrollbarFrame) 1.40 + 1.41 +NS_QUERYFRAME_HEAD(nsScrollbarFrame) 1.42 + NS_QUERYFRAME_ENTRY(nsScrollbarFrame) 1.43 +NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame) 1.44 + 1.45 +void 1.46 +nsScrollbarFrame::Init(nsIContent* aContent, 1.47 + nsIFrame* aParent, 1.48 + nsIFrame* aPrevInFlow) 1.49 +{ 1.50 + nsBoxFrame::Init(aContent, aParent, aPrevInFlow); 1.51 + 1.52 + // We want to be a reflow root since we use reflows to move the 1.53 + // slider. Any reflow inside the scrollbar frame will be a reflow to 1.54 + // move the slider and will thus not change anything outside of the 1.55 + // scrollbar or change the size of the scrollbar frame. 1.56 + mState |= NS_FRAME_REFLOW_ROOT; 1.57 +} 1.58 + 1.59 +nsresult 1.60 +nsScrollbarFrame::Reflow(nsPresContext* aPresContext, 1.61 + nsHTMLReflowMetrics& aDesiredSize, 1.62 + const nsHTMLReflowState& aReflowState, 1.63 + nsReflowStatus& aStatus) 1.64 +{ 1.65 + nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); 1.66 + NS_ENSURE_SUCCESS(rv, rv); 1.67 + 1.68 + // nsGfxScrollFrame may have told us to shrink to nothing. If so, make sure our 1.69 + // desired size agrees. 1.70 + if (aReflowState.AvailableWidth() == 0) { 1.71 + aDesiredSize.Width() = 0; 1.72 + } 1.73 + if (aReflowState.AvailableHeight() == 0) { 1.74 + aDesiredSize.Height() = 0; 1.75 + } 1.76 + 1.77 + return NS_OK; 1.78 +} 1.79 + 1.80 +nsIAtom* 1.81 +nsScrollbarFrame::GetType() const 1.82 +{ 1.83 + return nsGkAtoms::scrollbarFrame; 1.84 +} 1.85 + 1.86 +nsresult 1.87 +nsScrollbarFrame::AttributeChanged(int32_t aNameSpaceID, 1.88 + nsIAtom* aAttribute, 1.89 + int32_t aModType) 1.90 +{ 1.91 + nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, 1.92 + aModType); 1.93 + 1.94 + // if the current position changes, notify any nsGfxScrollFrame 1.95 + // parent we may have 1.96 + if (aAttribute != nsGkAtoms::curpos) 1.97 + return rv; 1.98 + 1.99 + nsIScrollableFrame* scrollable = do_QueryFrame(GetParent()); 1.100 + if (!scrollable) 1.101 + return rv; 1.102 + 1.103 + nsCOMPtr<nsIContent> kungFuDeathGrip(mContent); 1.104 + scrollable->CurPosAttributeChanged(mContent); 1.105 + return rv; 1.106 +} 1.107 + 1.108 +NS_IMETHODIMP 1.109 +nsScrollbarFrame::HandlePress(nsPresContext* aPresContext, 1.110 + WidgetGUIEvent* aEvent, 1.111 + nsEventStatus* aEventStatus) 1.112 +{ 1.113 + return NS_OK; 1.114 +} 1.115 + 1.116 +NS_IMETHODIMP 1.117 +nsScrollbarFrame::HandleMultiplePress(nsPresContext* aPresContext, 1.118 + WidgetGUIEvent* aEvent, 1.119 + nsEventStatus* aEventStatus, 1.120 + bool aControlHeld) 1.121 +{ 1.122 + return NS_OK; 1.123 +} 1.124 + 1.125 +NS_IMETHODIMP 1.126 +nsScrollbarFrame::HandleDrag(nsPresContext* aPresContext, 1.127 + WidgetGUIEvent* aEvent, 1.128 + nsEventStatus* aEventStatus) 1.129 +{ 1.130 + return NS_OK; 1.131 +} 1.132 + 1.133 +NS_IMETHODIMP 1.134 +nsScrollbarFrame::HandleRelease(nsPresContext* aPresContext, 1.135 + WidgetGUIEvent* aEvent, 1.136 + nsEventStatus* aEventStatus) 1.137 +{ 1.138 + return NS_OK; 1.139 +} 1.140 + 1.141 +void 1.142 +nsScrollbarFrame::SetScrollbarMediatorContent(nsIContent* aMediator) 1.143 +{ 1.144 + mScrollbarMediator = aMediator; 1.145 +} 1.146 + 1.147 +nsIScrollbarMediator* 1.148 +nsScrollbarFrame::GetScrollbarMediator() 1.149 +{ 1.150 + if (!mScrollbarMediator) 1.151 + return nullptr; 1.152 + nsIFrame* f = mScrollbarMediator->GetPrimaryFrame(); 1.153 + 1.154 + // check if the frame is a scroll frame. If so, get the scrollable frame 1.155 + // inside it. 1.156 + nsIScrollableFrame* scrollFrame = do_QueryFrame(f); 1.157 + if (scrollFrame) { 1.158 + f = scrollFrame->GetScrolledFrame(); 1.159 + } 1.160 + 1.161 + nsIScrollbarMediator* sbm = do_QueryFrame(f); 1.162 + return sbm; 1.163 +} 1.164 + 1.165 +nsresult 1.166 +nsScrollbarFrame::GetMargin(nsMargin& aMargin) 1.167 +{ 1.168 + aMargin.SizeTo(0,0,0,0); 1.169 + 1.170 + if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) { 1.171 + nsPresContext* presContext = PresContext(); 1.172 + nsITheme* theme = presContext->GetTheme(); 1.173 + if (theme) { 1.174 + nsIntSize size; 1.175 + bool isOverridable; 1.176 + nsRefPtr<nsRenderingContext> rc = 1.177 + presContext->PresShell()->CreateReferenceRenderingContext(); 1.178 + theme->GetMinimumWidgetSize(rc, this, NS_THEME_SCROLLBAR, &size, 1.179 + &isOverridable); 1.180 + if (IsHorizontal()) { 1.181 + aMargin.top = -presContext->DevPixelsToAppUnits(size.height); 1.182 + } 1.183 + else { 1.184 + if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) { 1.185 + aMargin.right = -presContext->DevPixelsToAppUnits(size.width); 1.186 + } 1.187 + else { 1.188 + aMargin.left = -presContext->DevPixelsToAppUnits(size.width); 1.189 + } 1.190 + } 1.191 + return NS_OK; 1.192 + } 1.193 + } 1.194 + 1.195 + return nsBox::GetMargin(aMargin); 1.196 +}