diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-13 03:44:31 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-13 03:44:31 +0000 |
commit | dd6afcae7bffda8cf9a70e01191f0a08e5a0f7e3 (patch) | |
tree | 38c47aa3ba8908b05d8010f4f0853f1a71af4ac0 /content | |
parent | 48352a17719783565d2e7c97de5eeddd6b0e9b8d (diff) | |
download | chromium_src-dd6afcae7bffda8cf9a70e01191f0a08e5a0f7e3.zip chromium_src-dd6afcae7bffda8cf9a70e01191f0a08e5a0f7e3.tar.gz chromium_src-dd6afcae7bffda8cf9a70e01191f0a08e5a0f7e3.tar.bz2 |
Pipe "is pinned to left/right", "has horizontal/vertical scrollbar",
"number of wheel handlers" to browser process.
We want to implement two-finger-swipe for history like safari does on
os x lion. The way this works is:
* If a page has no horizontal scrollbars, or the page is all the way
to the left, scrolling to the left will go back in history instead.
* Same for right/forward.
Hence, this data needs to be available in the browser process.
This is modelled after the WebKit2 functions
WKPageIsPinnedToLeftSide(), WKPageIsPinnedToRightSide(),
WKPageHasHorizontalScrollbar(), and
webPageProxy::willHandleHorizontalScrollEvents().
Depends on https://bugs.webkit.org/show_bug.cgi?id=66094
BUG=90228
TEST=No observable effect yet
Review URL: http://codereview.chromium.org/7635011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/render_view_host.cc | 20 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host.h | 5 | ||||
-rw-r--r-- | content/common/view_messages.h | 14 | ||||
-rw-r--r-- | content/renderer/render_view.cc | 50 | ||||
-rw-r--r-- | content/renderer/render_view.h | 15 |
5 files changed, 104 insertions, 0 deletions
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 3d360a2..8af8ed8 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -692,6 +692,12 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL) IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, OnMsgDidContentsPreferredSizeChange) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollbarsForMainFrame, + OnMsgDidChangeScrollbarsForMainFrame) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame, + OnMsgDidChangeScrollOffsetPinningForMainFrame) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumWheelEvents, + OnMsgDidChangeNumWheelEvents) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage, OnMsgRunJavaScriptMessage) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm, @@ -1001,6 +1007,20 @@ void RenderViewHost::OnMsgDidContentsPreferredSizeChange( view->UpdatePreferredSize(new_size); } +void RenderViewHost::OnMsgDidChangeScrollbarsForMainFrame( + bool has_horizontal_scrollbar, bool has_vertical_scrollbar) { + // TODO(thakis): Implement, http://crbug.com/90228 +} + +void RenderViewHost::OnMsgDidChangeScrollOffsetPinningForMainFrame( + bool is_pinned_to_left, bool is_pinned_to_right) { + // TODO(thakis): Implement, http://crbug.com/90228 +} + +void RenderViewHost::OnMsgDidChangeNumWheelEvents(int count) { + // TODO(thakis): Implement, http://crbug.com/90228 +} + void RenderViewHost::OnMsgSelectionChanged(const std::string& text, const ui::Range& range, const gfx::Point& start, diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index 17f560a..d5566c0 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -430,6 +430,11 @@ class RenderViewHost : public RenderWidgetHost { void OnMsgOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); void OnMsgDidContentsPreferredSizeChange(const gfx::Size& new_size); + void OnMsgDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar, + bool has_vertical_scrollbar); + void OnMsgDidChangeScrollOffsetPinningForMainFrame(bool is_pinned_to_left, + bool is_pinned_to_right); + void OnMsgDidChangeNumWheelEvents(int count); void OnMsgSelectionChanged(const std::string& text, const ui::Range& range, const gfx::Point& start, const gfx::Point& end); void OnMsgPasteFromSelectionClipboard(); diff --git a/content/common/view_messages.h b/content/common/view_messages.h index eca2d1a..964579f 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1662,6 +1662,20 @@ IPC_MESSAGE_ROUTED3(ViewHostMsg_OpenURL, IPC_MESSAGE_ROUTED1(ViewHostMsg_DidContentsPreferredSizeChange, gfx::Size /* pref_size */) +// Notifies that the scrollbars-visible state of the content changed. +IPC_MESSAGE_ROUTED2(ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame, + bool /* has_horizontal_scrollbar */, + bool /* has_vertical_scrollbar */) + +// Notifies that the pinned-to-side state of the content changed. +IPC_MESSAGE_ROUTED2(ViewHostMsg_DidChangeScrollbarsForMainFrame, + bool /* pinned_to_left */, + bool /* pinned_to_right */) + +// Notifies that the number of JavaScript scroll handlers changed. +IPC_MESSAGE_ROUTED1(ViewHostMsg_DidChangeNumWheelEvents, + int /* count */) + // A message from HTML-based UI. When (trusted) Javascript calls // send(message, args), this message is sent to the browser. IPC_MESSAGE_ROUTED3(ViewHostMsg_WebUISend, diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc index a09f732..4344aba 100644 --- a/content/renderer/render_view.cc +++ b/content/renderer/render_view.cc @@ -353,6 +353,10 @@ RenderView::RenderView(RenderThreadBase* render_thread, history_list_offset_(-1), history_list_length_(0), target_url_status_(TARGET_NONE), + cached_is_main_frame_pinned_to_left_(false), + cached_is_main_frame_pinned_to_right_(false), + cached_has_main_frame_horizontal_scrollbar_(false), + cached_has_main_frame_vertical_scrollbar_(false), ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), @@ -2884,8 +2888,53 @@ void RenderView::CheckPreferredSize() { preferred_size_)); } +void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { + if (webview()->mainFrame() != frame) + return; + WebView* frameView = frame->view(); + if (!frameView) + return; + + bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar(); + bool has_vertical_scrollbar = frame->hasVerticalScrollbar(); + + if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ || + has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) { + Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame( + routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar)); + + cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar; + cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar; + } +} + +void RenderView::UpdateScrollState(WebFrame* frame) { + WebSize offset = frame->scrollOffset(); + WebSize minimum_offset = frame->minimumScrollOffset(); + WebSize maximum_offset = frame->maximumScrollOffset(); + + bool is_pinned_to_left = offset.width <= minimum_offset.width; + bool is_pinned_to_right = offset.width >= maximum_offset.width; + + if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ || + is_pinned_to_right != cached_is_main_frame_pinned_to_right_) { + Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame( + routing_id_, is_pinned_to_left, is_pinned_to_right)); + + cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; + cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; + } +} + void RenderView::didChangeScrollOffset(WebFrame* frame) { StartNavStateSyncTimerIfNecessary(); + + if (webview()->mainFrame() == frame) + UpdateScrollState(frame); +} + +void RenderView::numberOfWheelEventHandlersChanged(unsigned num_handlers) { + Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers)); } void RenderView::reportFindInPageMatchCount(int request_id, int count, @@ -3879,6 +3928,7 @@ void RenderView::OnResize(const gfx::Size& new_size, webview()->mainFrame()->setCanHaveScrollbars( should_display_scrollbars(new_size.width(), new_size.height())); } + UpdateScrollState(webview()->mainFrame()); } RenderWidget::OnResize(new_size, resizer_rect); diff --git a/content/renderer/render_view.h b/content/renderer/render_view.h index b34322c..9a329c5 100644 --- a/content/renderer/render_view.h +++ b/content/renderer/render_view.h @@ -559,6 +559,9 @@ class RenderView : public RenderWidget, unsigned long long event_id); virtual void didUpdateLayout(WebKit::WebFrame* frame); virtual void didChangeScrollOffset(WebKit::WebFrame* frame); + virtual void numberOfWheelEventHandlersChanged(unsigned num_handlers); + virtual void didChangeContentsSize(WebKit::WebFrame* frame, + const WebKit::WebSize& size); virtual void reportFindInPageMatchCount(int request_id, int count, bool final_update); @@ -732,6 +735,9 @@ class RenderView : public RenderWidget, // Send queued accessibility notifications from the renderer to the browser. void SendPendingAccessibilityNotifications(); + // Called when the "pinned to left/right edge" state needs to be updated. + void UpdateScrollState(WebKit::WebFrame* frame); + // IPC message handlers ------------------------------------------------------ // // The documentation for these functions should be in @@ -1084,6 +1090,15 @@ class RenderView : public RenderWidget, // states for the sizes). base::OneShotTimer<RenderView> check_preferred_size_timer_; + // These store the "is main frame is scrolled all the way to the left + // or right" state that was last sent to the browser. + bool cached_is_main_frame_pinned_to_left_; + bool cached_is_main_frame_pinned_to_right_; + + // These store the "has scrollbars" state last sent to the browser. + bool cached_has_main_frame_horizontal_scrollbar_; + bool cached_has_main_frame_vertical_scrollbar_; + #if defined(OS_MACOSX) // Track the fake plugin window handles allocated on the browser side for // the accelerated compositor and (currently) accelerated plugins so that |