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

Side by Side Diff: chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm

Issue 9296040: mac: Always do history swiping on the NTP on lion devices with touchpad. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: true/false -> YES/NO Created 8 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegat e.h" 5 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegat e.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/debugger/devtools_window.h" 10 #include "chrome/browser/debugger/devtools_window.h"
11 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" 11 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
14 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" 14 #import "chrome/browser/ui/cocoa/history_overlay_controller.h"
15 #import "chrome/browser/ui/cocoa/view_id_util.h" 15 #import "chrome/browser/ui/cocoa/view_id_util.h"
16 #include "chrome/common/spellcheck_messages.h" 16 #include "chrome/common/spellcheck_messages.h"
17 #include "chrome/common/url_constants.h"
17 #include "content/browser/mac/closure_blocks_leopard_compat.h" 18 #include "content/browser/mac/closure_blocks_leopard_compat.h"
18 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/renderer_host/render_widget_host.h" 20 #include "content/browser/renderer_host/render_widget_host.h"
20 #include "content/browser/renderer_host/render_widget_host_view.h" 21 #include "content/browser/renderer_host/render_widget_host_view.h"
21 #include "content/public/browser/render_view_host_observer.h" 22 #include "content/public/browser/render_view_host_observer.h"
23 #include "content/public/browser/web_contents.h"
22 24
23 // Declare things that are part of the 10.7 SDK. 25 // Declare things that are part of the 10.7 SDK.
24 #if !defined(MAC_OS_X_VERSION_10_7) || \ 26 #if !defined(MAC_OS_X_VERSION_10_7) || \
25 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 27 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
26 enum { 28 enum {
27 NSEventPhaseNone = 0, // event not associated with a phase. 29 NSEventPhaseNone = 0, // event not associated with a phase.
28 NSEventPhaseBegan = 0x1 << 0, 30 NSEventPhaseBegan = 0x1 << 0,
29 NSEventPhaseStationary = 0x1 << 1, 31 NSEventPhaseStationary = 0x1 << 1,
30 NSEventPhaseChanged = 0x1 << 2, 32 NSEventPhaseChanged = 0x1 << 2,
31 NSEventPhaseEnded = 0x1 << 3, 33 NSEventPhaseEnded = 0x1 << 3,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 131 }
130 132
131 - (BOOL)handleEvent:(NSEvent*)event { 133 - (BOOL)handleEvent:(NSEvent*)event {
132 if ([event type] == NSScrollWheel) 134 if ([event type] == NSScrollWheel)
133 return [self maybeHandleHistorySwiping:event]; 135 return [self maybeHandleHistorySwiping:event];
134 136
135 return NO; 137 return NO;
136 } 138 }
137 139
138 - (void)gotUnhandledWheelEvent { 140 - (void)gotUnhandledWheelEvent {
139 gotUnhandledWheelEvent_ = true; 141 gotUnhandledWheelEvent_ = YES;
140 } 142 }
141 143
142 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right { 144 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right {
143 isPinnedLeft_ = left; 145 isPinnedLeft_ = left;
144 isPinnedRight_ = right; 146 isPinnedRight_ = right;
145 } 147 }
146 148
147 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar { 149 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar {
148 hasHorizontalScrollbar_ = has_horizontal_scrollbar; 150 hasHorizontalScrollbar_ = has_horizontal_scrollbar;
149 } 151 }
150 152
151 // Checks if |theEvent| should trigger history swiping, and if so, does 153 // Checks if |theEvent| should trigger history swiping, and if so, does
152 // history swiping. Returns YES if the event was consumed or NO if it should 154 // history swiping. Returns YES if the event was consumed or NO if it should
153 // be passed on to the renderer. 155 // be passed on to the renderer.
154 - (BOOL)maybeHandleHistorySwiping:(NSEvent*)theEvent { 156 - (BOOL)maybeHandleHistorySwiping:(NSEvent*)theEvent {
155 BOOL canUseLionApis = [theEvent respondsToSelector:@selector(phase)]; 157 BOOL canUseLionApis = [theEvent respondsToSelector:@selector(phase)];
156 if (!canUseLionApis) 158 if (!canUseLionApis)
157 return NO; 159 return NO;
158 160
159 // Scroll events always go to the web first, and can only trigger history 161 // Scroll events always go to the web first, and can only trigger history
160 // swiping if they come back unhandled. 162 // swiping if they come back unhandled.
161 if ([theEvent phase] == NSEventPhaseBegan) { 163 if ([theEvent phase] == NSEventPhaseBegan) {
162 totalScrollDelta_ = NSZeroSize; 164 totalScrollDelta_ = NSZeroSize;
163 gotUnhandledWheelEvent_ = false; 165 gotUnhandledWheelEvent_ = NO;
164 } 166 }
165 167
166 if (!render_widget_host_ || !render_widget_host_->IsRenderView()) 168 if (!render_widget_host_ || !render_widget_host_->IsRenderView())
167 return NO; 169 return NO;
168 bool isDevtoolsRwhv = DevToolsWindow::IsDevToolsWindow( 170 bool isDevtoolsRwhv = DevToolsWindow::IsDevToolsWindow(
169 static_cast<RenderViewHost*>(render_widget_host_)); 171 static_cast<RenderViewHost*>(render_widget_host_));
170 if (isDevtoolsRwhv) 172 if (isDevtoolsRwhv)
171 return NO; 173 return NO;
172 174
175 // TODO(thakis): This is wrong, as it will navigate the frontmost browser
176 // for swipe events on background windows. It also navigates the frontmost
177 // browser for swipes on extensions popups. And it's a dependency problem,
178 // too. http://crbug.com/102541
179 Browser* browser = BrowserList::GetLastActive();
180
181 if (browser && [NSEvent isSwipeTrackingFromScrollEventsEnabled]) {
182 content::WebContents* contents = browser->GetSelectedWebContents();
183 if (contents && contents->GetURL() == GURL(chrome::kChromeUINewTabURL)) {
184 // Always do history navigation on the NTP if it's enabled.
185 gotUnhandledWheelEvent_ = YES;
186 }
187 }
188
173 if (gotUnhandledWheelEvent_ && 189 if (gotUnhandledWheelEvent_ &&
174 [NSEvent isSwipeTrackingFromScrollEventsEnabled] && 190 [NSEvent isSwipeTrackingFromScrollEventsEnabled] &&
175 [theEvent phase] == NSEventPhaseChanged) { 191 [theEvent phase] == NSEventPhaseChanged) {
176 totalScrollDelta_.width += [theEvent scrollingDeltaX]; 192 totalScrollDelta_.width += [theEvent scrollingDeltaX];
177 totalScrollDelta_.height += [theEvent scrollingDeltaY]; 193 totalScrollDelta_.height += [theEvent scrollingDeltaY];
178 194
179 bool isHorizontalGesture = 195 bool isHorizontalGesture =
180 std::abs(totalScrollDelta_.width) > std::abs(totalScrollDelta_.height); 196 std::abs(totalScrollDelta_.width) > std::abs(totalScrollDelta_.height);
181 197
182 bool isRightScroll = [theEvent scrollingDeltaX] < 0; 198 bool isRightScroll = [theEvent scrollingDeltaX] < 0;
183 bool goForward = isRightScroll; 199 bool goForward = isRightScroll;
184 bool canGoBack = false, canGoForward = false; 200 bool canGoBack = false, canGoForward = false;
185 if (Browser* browser = BrowserList::GetLastActive()) { 201 if (browser) {
186 canGoBack = browser->CanGoBack(); 202 canGoBack = browser->CanGoBack();
187 canGoForward = browser->CanGoForward(); 203 canGoForward = browser->CanGoForward();
188 } 204 }
189 205
190 // If "forward" is inactive and the user rubber-bands to the right, 206 // If "forward" is inactive and the user rubber-bands to the right,
191 // "isPinnedLeft" will be false. When the user then rubber-bands to the 207 // "isPinnedLeft" will be false. When the user then rubber-bands to the
192 // left in the same gesture, that should trigger history immediately if 208 // left in the same gesture, that should trigger history immediately if
193 // there's no scrollbar, hence the check for hasHorizontalScrollbar_. 209 // there's no scrollbar, hence the check for hasHorizontalScrollbar_.
194 bool shouldGoBack = isPinnedLeft_ || !hasHorizontalScrollbar_; 210 bool shouldGoBack = isPinnedLeft_ || !hasHorizontalScrollbar_;
195 bool shouldGoForward = isPinnedRight_ || !hasHorizontalScrollbar_; 211 bool shouldGoForward = isPinnedRight_ || !hasHorizontalScrollbar_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 272
257 [historyOverlay setProgress:gestureAmount]; 273 [historyOverlay setProgress:gestureAmount];
258 if (isComplete) { 274 if (isComplete) {
259 [historyOverlay dismiss]; 275 [historyOverlay dismiss];
260 [historyOverlay release]; 276 [historyOverlay release];
261 } 277 }
262 }]; 278 }];
263 return YES; 279 return YES;
264 } 280 }
265 } 281 }
266 return NO; 282 return gotUnhandledWheelEvent_;
267 } 283 }
268 284
269 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item 285 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item
270 isValidItem:(BOOL*)valid { 286 isValidItem:(BOOL*)valid {
271 SEL action = [item action]; 287 SEL action = [item action];
272 288
273 // For now, this action is always enabled for render view; 289 // For now, this action is always enabled for render view;
274 // this is sub-optimal. 290 // this is sub-optimal.
275 // TODO(suzhe): Plumb the "can*" methods up from WebCore. 291 // TODO(suzhe): Plumb the "can*" methods up from WebCore.
276 if (action == @selector(checkSpelling:)) { 292 if (action == @selector(checkSpelling:)) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 357 }
342 358
343 - (void)spellCheckEnabled:(BOOL)enabled checked:(BOOL)checked { 359 - (void)spellCheckEnabled:(BOOL)enabled checked:(BOOL)checked {
344 spellcheck_enabled_ = enabled; 360 spellcheck_enabled_ = enabled;
345 spellcheck_checked_ = checked; 361 spellcheck_checked_ = checked;
346 } 362 }
347 363
348 // END Spellchecking methods 364 // END Spellchecking methods
349 365
350 @end 366 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698