Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 gotUnhandledWheelEvent_ = false; | 165 gotUnhandledWheelEvent_ = false; |
| 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_ = true; | |
|
Robert Sesek
2012/01/30 18:09:22
nit: should be YES
Nico
2012/01/30 18:11:22
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 Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |