Bug 1199885 - Part 13: Let nsSliderFrame trigger async scrolling via StartScrollbarDrag. r=kats

--HG--
extra : commitid : LMXLmzjgQ4
This commit is contained in:
Benoit Girard 2015-09-28 17:00:25 -04:00
Родитель 60376c4a70
Коммит b3c2569202
2 изменённых файлов: 56 добавлений и 0 удалений

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIDOMMouseEvent.h" #include "nsIDOMMouseEvent.h"
#include "nsScrollbarButtonFrame.h" #include "nsScrollbarButtonFrame.h"
#include "nsISliderListener.h" #include "nsISliderListener.h"
#include "nsIScrollableFrame.h"
#include "nsIScrollbarMediator.h" #include "nsIScrollbarMediator.h"
#include "nsScrollbarFrame.h" #include "nsScrollbarFrame.h"
#include "nsRepeatService.h" #include "nsRepeatService.h"
@ -35,9 +36,13 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h" #include "mozilla/LookAndFeel.h"
#include "mozilla/MouseEvents.h" #include "mozilla/MouseEvents.h"
#include "mozilla/layers/AsyncDragMetrics.h"
#include "mozilla/layers/InputAPZContext.h"
#include <algorithm> #include <algorithm>
using namespace mozilla; using namespace mozilla;
using mozilla::layers::AsyncDragMetrics;
using mozilla::layers::InputAPZContext;
bool nsSliderFrame::gMiddlePref = false; bool nsSliderFrame::gMiddlePref = false;
int32_t nsSliderFrame::gSnapMultiplier; int32_t nsSliderFrame::gSnapMultiplier;
@ -893,6 +898,53 @@ nsSliderMediator::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK; return NS_OK;
} }
bool
nsSliderFrame::StartAPZDrag(WidgetGUIEvent* aEvent)
{
if (!gfxPlatform::GetPlatform()->SupportsApzDragInput()) {
return false;
}
nsContainerFrame* cf = GetScrollbar()->GetParent();
if (!cf) {
return false;
}
nsIContent* scrollableContent = cf->GetContent();
if (!scrollableContent) {
return false;
}
mozilla::layers::FrameMetrics::ViewID scrollTargetId;
bool hasID = nsLayoutUtils::FindIDFor(scrollableContent, &scrollTargetId);
bool hasAPZView = hasID && (scrollTargetId != layers::FrameMetrics::NULL_SCROLL_ID);
if (!hasAPZView) {
return false;
}
nsIFrame* scrollbarBox = GetScrollbar();
nsCOMPtr<nsIContent> scrollbar = GetContentOfBox(scrollbarBox);
// This rect is the range in which the scroll thumb can slide in.
nsRect sliderTrack = GetRect() - scrollbarBox->GetPosition();
CSSIntRect sliderTrackCSS = CSSIntRect::FromAppUnitsRounded(sliderTrack);
uint64_t inputblockId = InputAPZContext::GetInputBlockId();
uint32_t presShellId = PresContext()->PresShell()->GetPresShellId();
AsyncDragMetrics dragMetrics(scrollTargetId, presShellId, inputblockId,
NSAppUnitsToIntPixels(mDragStart,
float(AppUnitsPerCSSPixel())),
sliderTrackCSS,
IsHorizontal() ? AsyncDragMetrics::HORIZONTAL :
AsyncDragMetrics::VERTICAL);
// When we start an APZ drag, we wont get mouse events for the drag.
// APZ will consume them all and only notify us of the new scroll position.
this->GetNearestWidget()->StartAsyncScrollbarDrag(dragMetrics);
return true;
}
nsresult nsresult
nsSliderFrame::StartDrag(nsIDOMEvent* aEvent) nsSliderFrame::StartDrag(nsIDOMEvent* aEvent)
{ {
@ -960,6 +1012,8 @@ nsSliderFrame::StartDrag(nsIDOMEvent* aEvent)
mDragStart = pos - mThumbStart; mDragStart = pos - mThumbStart;
StartAPZDrag(event);
#ifdef DEBUG_SLIDER #ifdef DEBUG_SLIDER
printf("Pressed mDragStart=%d\n",mDragStart); printf("Pressed mDragStart=%d\n",mDragStart);
#endif #endif

Просмотреть файл

@ -100,6 +100,8 @@ public:
nsresult StartDrag(nsIDOMEvent* aEvent); nsresult StartDrag(nsIDOMEvent* aEvent);
nsresult StopDrag(); nsresult StopDrag();
bool StartAPZDrag(mozilla::WidgetGUIEvent* aEvent);
static int32_t GetCurrentPosition(nsIContent* content); static int32_t GetCurrentPosition(nsIContent* content);
static int32_t GetMinPosition(nsIContent* content); static int32_t GetMinPosition(nsIContent* content);
static int32_t GetMaxPosition(nsIContent* content); static int32_t GetMaxPosition(nsIContent* content);