Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBox.cpp

Issue 2484563003: Determine the layoutobject of middleClickAutoscroll by the scroll direction. (Closed)
Patch Set: Better tests. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 layoutObject->document().localOwner()) 1036 layoutObject->document().localOwner())
1037 layoutObject = layoutObject->document().localOwner()->layoutObject(); 1037 layoutObject = layoutObject->document().localOwner()->layoutObject();
1038 else 1038 else
1039 layoutObject = layoutObject->parent(); 1039 layoutObject = layoutObject->parent();
1040 } 1040 }
1041 1041
1042 return layoutObject && layoutObject->isBox() ? toLayoutBox(layoutObject) 1042 return layoutObject && layoutObject->isBox() ? toLayoutBox(layoutObject)
1043 : nullptr; 1043 : nullptr;
1044 } 1044 }
1045 1045
1046 static inline int adjustedScrollDelta(int beginningDelta) {
1047 // This implemention matches Firefox's.
1048 // http://mxr.mozilla.org/firefox/source/toolkit/content/widgets/browser.xml#8 56.
1049 const int speedReducer = 12;
1050
1051 int adjustedDelta = beginningDelta / speedReducer;
1052 if (adjustedDelta > 1)
1053 adjustedDelta = static_cast<int>(adjustedDelta *
1054 sqrt(static_cast<double>(adjustedDelta))) -
1055 1;
1056 else if (adjustedDelta < -1)
1057 adjustedDelta =
1058 static_cast<int>(adjustedDelta *
1059 sqrt(static_cast<double>(-adjustedDelta))) +
1060 1;
1061
1062 return adjustedDelta;
1063 }
1064
1065 static inline IntSize adjustedScrollDelta(const IntSize& delta) {
1066 return IntSize(adjustedScrollDelta(delta.width()),
1067 adjustedScrollDelta(delta.height()));
1068 }
1069
1070 void LayoutBox::middleClickAutoscroll(const IntPoint& sourcePoint) {
1071 LocalFrame* frame = this->frame();
1072 if (!frame)
1073 return;
1074
1075 IntPoint lastKnownMousePosition =
1076 frame->eventHandler().lastKnownMousePosition();
1077
1078 // We need to check if the last known mouse position is out of the window.
1079 // When the mouse is out of the window, the position is incoherent
1080 static IntPoint previousMousePosition;
1081 if (lastKnownMousePosition.x() < 0 || lastKnownMousePosition.y() < 0)
1082 lastKnownMousePosition = previousMousePosition;
1083 else
1084 previousMousePosition = lastKnownMousePosition;
1085
1086 IntSize delta = lastKnownMousePosition - sourcePoint;
1087
1088 // at the center we let the space for the icon.
1089 if (abs(delta.width()) <= AutoscrollController::noMiddleClickAutoscrollRadius)
1090 delta.setWidth(0);
1091 if (abs(delta.height()) <=
1092 AutoscrollController::noMiddleClickAutoscrollRadius)
1093 delta.setHeight(0);
1094 scroll(ScrollByPixel, FloatSize(adjustedScrollDelta(delta)));
1095 }
1096
1097 void LayoutBox::scrollByRecursively(const ScrollOffset& delta) { 1046 void LayoutBox::scrollByRecursively(const ScrollOffset& delta) {
1098 if (delta.isZero()) 1047 if (delta.isZero())
1099 return; 1048 return;
1100 1049
1101 bool restrictedByLineClamp = false; 1050 bool restrictedByLineClamp = false;
1102 if (parent()) 1051 if (parent())
1103 restrictedByLineClamp = !parent()->style()->lineClamp().isNone(); 1052 restrictedByLineClamp = !parent()->style()->lineClamp().isNone();
1104 1053
1105 if (hasOverflowClip() && !restrictedByLineClamp) { 1054 if (hasOverflowClip() && !restrictedByLineClamp) {
1106 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); 1055 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea();
(...skipping 4537 matching lines...) Expand 10 before | Expand all | Expand 10 after
5644 LayoutRect rect = frameRect(); 5593 LayoutRect rect = frameRect();
5645 5594
5646 LayoutBlock* block = containingBlock(); 5595 LayoutBlock* block = containingBlock();
5647 if (block) 5596 if (block)
5648 block->adjustChildDebugRect(rect); 5597 block->adjustChildDebugRect(rect);
5649 5598
5650 return rect; 5599 return rect;
5651 } 5600 }
5652 5601
5653 } // namespace blink 5602 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.h ('k') | third_party/WebKit/Source/core/page/AutoscrollController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698