| 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" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 [view_delegate_ spellCheckEnabled:enabled checked:checked]; | 101 [view_delegate_ spellCheckEnabled:enabled checked:checked]; |
| 102 } | 102 } |
| 103 | 103 |
| 104 ChromeRenderWidgetHostViewMacDelegate* view_delegate_; | 104 ChromeRenderWidgetHostViewMacDelegate* view_delegate_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 } // namespace ChromeRenderWidgetHostViewMacDelegateInternal | 107 } // namespace ChromeRenderWidgetHostViewMacDelegateInternal |
| 108 | 108 |
| 109 @implementation ChromeRenderWidgetHostViewMacDelegate | 109 @implementation ChromeRenderWidgetHostViewMacDelegate |
| 110 | 110 |
| 111 - (id)initWithRenderWidgetHost:(RenderWidgetHost*)render_widget_host { | 111 - (id)initWithRenderWidgetHost:(RenderWidgetHost*)renderWidgetHost { |
| 112 self = [super init]; | 112 self = [super init]; |
| 113 if (self) { | 113 if (self) { |
| 114 render_widget_host_ = render_widget_host; | 114 renderWidgetHost_ = renderWidgetHost; |
| 115 NSView* native_view = render_widget_host_->view()->GetNativeView(); | 115 NSView* nativeView = renderWidgetHost_->view()->GetNativeView(); |
| 116 view_id_util::SetID(native_view, VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); | 116 view_id_util::SetID(nativeView, VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); |
| 117 | 117 |
| 118 if (render_widget_host_->IsRenderView()) { | 118 if (renderWidgetHost_->IsRenderView()) { |
| 119 spelling_observer_.reset( | 119 spellingObserver_.reset( |
| 120 new ChromeRenderWidgetHostViewMacDelegateInternal:: | 120 new ChromeRenderWidgetHostViewMacDelegateInternal:: |
| 121 SpellCheckRenderViewObserver( | 121 SpellCheckRenderViewObserver( |
| 122 static_cast<RenderViewHost*>(render_widget_host_), self)); | 122 static_cast<RenderViewHost*>(renderWidgetHost_), self)); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return self; | 125 return self; |
| 126 } | 126 } |
| 127 | 127 |
| 128 - (void)viewGone:(NSView*)view { | 128 - (void)viewGone:(NSView*)view { |
| 129 view_id_util::UnsetID(view); | 129 view_id_util::UnsetID(view); |
| 130 [self autorelease]; | 130 [self autorelease]; |
| 131 } | 131 } |
| 132 | 132 |
| 133 - (BOOL)handleEvent:(NSEvent*)event { | 133 - (BOOL)handleEvent:(NSEvent*)event { |
| 134 if ([event type] == NSScrollWheel) | 134 if ([event type] == NSScrollWheel) |
| 135 return [self maybeHandleHistorySwiping:event]; | 135 return [self maybeHandleHistorySwiping:event]; |
| 136 | 136 |
| 137 return NO; | 137 return NO; |
| 138 } | 138 } |
| 139 | 139 |
| 140 - (void)gotUnhandledWheelEvent { | 140 - (void)gotUnhandledWheelEvent { |
| 141 gotUnhandledWheelEvent_ = YES; | 141 gotUnhandledWheelEvent_ = YES; |
| 142 } | 142 } |
| 143 | 143 |
| 144 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right { | 144 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right { |
| 145 isPinnedLeft_ = left; | 145 isPinnedLeft_ = left; |
| 146 isPinnedRight_ = right; | 146 isPinnedRight_ = right; |
| 147 } | 147 } |
| 148 | 148 |
| 149 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar { | 149 - (void)setHasHorizontalScrollbar:(BOOL)hasHorizontalScrollbar { |
| 150 hasHorizontalScrollbar_ = has_horizontal_scrollbar; | 150 hasHorizontalScrollbar_ = hasHorizontalScrollbar; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Checks if |theEvent| should trigger history swiping, and if so, does | 153 // Checks if |theEvent| should trigger history swiping, and if so, does |
| 154 // 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 |
| 155 // be passed on to the renderer. | 155 // be passed on to the renderer. |
| 156 - (BOOL)maybeHandleHistorySwiping:(NSEvent*)theEvent { | 156 - (BOOL)maybeHandleHistorySwiping:(NSEvent*)theEvent { |
| 157 BOOL canUseLionApis = [theEvent respondsToSelector:@selector(phase)]; | 157 BOOL canUseLionApis = [theEvent respondsToSelector:@selector(phase)]; |
| 158 if (!canUseLionApis) | 158 if (!canUseLionApis) |
| 159 return NO; | 159 return NO; |
| 160 | 160 |
| 161 // 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 |
| 162 // swiping if they come back unhandled. | 162 // swiping if they come back unhandled. |
| 163 if ([theEvent phase] == NSEventPhaseBegan) { | 163 if ([theEvent phase] == NSEventPhaseBegan) { |
| 164 totalScrollDelta_ = NSZeroSize; | 164 totalScrollDelta_ = NSZeroSize; |
| 165 gotUnhandledWheelEvent_ = NO; | 165 gotUnhandledWheelEvent_ = NO; |
| 166 } | 166 } |
| 167 | 167 |
| 168 if (!render_widget_host_ || !render_widget_host_->IsRenderView()) | 168 if (!renderWidgetHost_ || !renderWidgetHost_->IsRenderView()) |
| 169 return NO; | 169 return NO; |
| 170 if (DevToolsWindow::IsDevToolsWindow( | 170 if (DevToolsWindow::IsDevToolsWindow( |
| 171 static_cast<RenderViewHost*>(render_widget_host_))) { | 171 static_cast<RenderViewHost*>(renderWidgetHost_))) { |
| 172 return NO; | 172 return NO; |
| 173 } | 173 } |
| 174 | 174 |
| 175 BOOL suppressWheelEvent = NO; | 175 BOOL suppressWheelEvent = NO; |
| 176 Browser* browser = BrowserList::FindBrowserWithWindow([theEvent window]); | 176 Browser* browser = BrowserList::FindBrowserWithWindow([theEvent window]); |
| 177 if (browser && [NSEvent isSwipeTrackingFromScrollEventsEnabled]) { | 177 if (browser && [NSEvent isSwipeTrackingFromScrollEventsEnabled]) { |
| 178 content::WebContents* contents = browser->GetSelectedWebContents(); | 178 content::WebContents* contents = browser->GetSelectedWebContents(); |
| 179 if (contents && contents->GetURL() == GURL(chrome::kChromeUINewTabURL)) { | 179 if (contents && contents->GetURL() == GURL(chrome::kChromeUINewTabURL)) { |
| 180 // Always do history navigation on the NTP if it's enabled. | 180 // Always do history navigation on the NTP if it's enabled. |
| 181 gotUnhandledWheelEvent_ = YES; | 181 gotUnhandledWheelEvent_ = YES; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // in the wrong direction. | 246 // in the wrong direction. |
| 247 [theEvent trackSwipeEventWithOptions:NSEventSwipeTrackingLockDirection | 247 [theEvent trackSwipeEventWithOptions:NSEventSwipeTrackingLockDirection |
| 248 dampenAmountThresholdMin:-1 | 248 dampenAmountThresholdMin:-1 |
| 249 max:1 | 249 max:1 |
| 250 usingHandler:^(CGFloat gestureAmount, | 250 usingHandler:^(CGFloat gestureAmount, |
| 251 NSEventPhase phase, | 251 NSEventPhase phase, |
| 252 BOOL isComplete, | 252 BOOL isComplete, |
| 253 BOOL *stop) { | 253 BOOL *stop) { |
| 254 if (phase == NSEventPhaseBegan) { | 254 if (phase == NSEventPhaseBegan) { |
| 255 [historyOverlay showPanelForView: | 255 [historyOverlay showPanelForView: |
| 256 render_widget_host_->view()->GetNativeView()]; | 256 renderWidgetHost_->view()->GetNativeView()]; |
| 257 return; | 257 return; |
| 258 } | 258 } |
| 259 | 259 |
| 260 BOOL ended = phase == NSEventPhaseEnded; | 260 BOOL ended = phase == NSEventPhaseEnded; |
| 261 | 261 |
| 262 // Dismiss the panel before navigation for immediate visual feedback. | 262 // Dismiss the panel before navigation for immediate visual feedback. |
| 263 [historyOverlay setProgress:gestureAmount]; | 263 [historyOverlay setProgress:gestureAmount]; |
| 264 if (ended) | 264 if (ended) |
| 265 [historyOverlay dismiss]; | 265 [historyOverlay dismiss]; |
| 266 | 266 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 285 } | 285 } |
| 286 | 286 |
| 287 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item | 287 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item |
| 288 isValidItem:(BOOL*)valid { | 288 isValidItem:(BOOL*)valid { |
| 289 SEL action = [item action]; | 289 SEL action = [item action]; |
| 290 | 290 |
| 291 // For now, this action is always enabled for render view; | 291 // For now, this action is always enabled for render view; |
| 292 // this is sub-optimal. | 292 // this is sub-optimal. |
| 293 // TODO(suzhe): Plumb the "can*" methods up from WebCore. | 293 // TODO(suzhe): Plumb the "can*" methods up from WebCore. |
| 294 if (action == @selector(checkSpelling:)) { | 294 if (action == @selector(checkSpelling:)) { |
| 295 *valid = render_widget_host_->IsRenderView(); | 295 *valid = renderWidgetHost_->IsRenderView(); |
| 296 return YES; | 296 return YES; |
| 297 } | 297 } |
| 298 | 298 |
| 299 if (action == @selector(toggleContinuousSpellChecking:)) { | 299 if (action == @selector(toggleContinuousSpellChecking:)) { |
| 300 if ([(id)item respondsToSelector:@selector(setState:)]) { | 300 if ([(id)item respondsToSelector:@selector(setState:)]) { |
| 301 NSCellStateValue checked_state = | 301 NSCellStateValue checkedState = |
| 302 spellcheck_checked_ ? NSOnState : NSOffState; | 302 spellcheckChecked_ ? NSOnState : NSOffState; |
| 303 [(id)item setState:checked_state]; | 303 [(id)item setState:checkedState]; |
| 304 } | 304 } |
| 305 *valid = spellcheck_enabled_; | 305 *valid = spellcheckEnabled_; |
| 306 return YES; | 306 return YES; |
| 307 } | 307 } |
| 308 | 308 |
| 309 return NO; | 309 return NO; |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Spellchecking methods | 312 // Spellchecking methods |
| 313 // The next five methods are implemented here since this class is the first | 313 // The next five methods are implemented here since this class is the first |
| 314 // responder for anything in the browser. | 314 // responder for anything in the browser. |
| 315 | 315 |
| 316 // This message is sent whenever the user specifies that a word should be | 316 // This message is sent whenever the user specifies that a word should be |
| 317 // changed from the spellChecker. | 317 // changed from the spellChecker. |
| 318 - (void)changeSpelling:(id)sender { | 318 - (void)changeSpelling:(id)sender { |
| 319 // Grab the currently selected word from the spell panel, as this is the word | 319 // Grab the currently selected word from the spell panel, as this is the word |
| 320 // that we want to replace the selected word in the text with. | 320 // that we want to replace the selected word in the text with. |
| 321 NSString* newWord = [[sender selectedCell] stringValue]; | 321 NSString* newWord = [[sender selectedCell] stringValue]; |
| 322 if (newWord != nil) { | 322 if (newWord != nil) { |
| 323 render_widget_host_->Replace(base::SysNSStringToUTF16(newWord)); | 323 renderWidgetHost_->Replace(base::SysNSStringToUTF16(newWord)); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 // This message is sent by NSSpellChecker whenever the next word should be | 327 // This message is sent by NSSpellChecker whenever the next word should be |
| 328 // advanced to, either after a correction or clicking the "Find Next" button. | 328 // advanced to, either after a correction or clicking the "Find Next" button. |
| 329 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the | 329 // This isn't documented anywhere useful, like in NSSpellProtocol.h with the |
| 330 // other spelling panel methods. This is probably because Apple assumes that the | 330 // other spelling panel methods. This is probably because Apple assumes that the |
| 331 // the spelling panel will be used with an NSText, which will automatically | 331 // the spelling panel will be used with an NSText, which will automatically |
| 332 // catch this and advance to the next word for you. Thanks Apple. | 332 // catch this and advance to the next word for you. Thanks Apple. |
| 333 // This is also called from the Edit -> Spelling -> Check Spelling menu item. | 333 // This is also called from the Edit -> Spelling -> Check Spelling menu item. |
| 334 - (void)checkSpelling:(id)sender { | 334 - (void)checkSpelling:(id)sender { |
| 335 render_widget_host_->Send(new SpellCheckMsg_AdvanceToNextMisspelling( | 335 renderWidgetHost_->Send(new SpellCheckMsg_AdvanceToNextMisspelling( |
| 336 render_widget_host_->routing_id())); | 336 renderWidgetHost_->routing_id())); |
| 337 } | 337 } |
| 338 | 338 |
| 339 // This message is sent by the spelling panel whenever a word is ignored. | 339 // This message is sent by the spelling panel whenever a word is ignored. |
| 340 - (void)ignoreSpelling:(id)sender { | 340 - (void)ignoreSpelling:(id)sender { |
| 341 // Ideally, we would ask the current RenderView for its tag, but that would | 341 // Ideally, we would ask the current RenderView for its tag, but that would |
| 342 // mean making a blocking IPC call from the browser. Instead, | 342 // mean making a blocking IPC call from the browser. Instead, |
| 343 // spellcheck_mac::CheckSpelling remembers the last tag and | 343 // spellcheck_mac::CheckSpelling remembers the last tag and |
| 344 // spellcheck_mac::IgnoreWord assumes that is the correct tag. | 344 // spellcheck_mac::IgnoreWord assumes that is the correct tag. |
| 345 NSString* wordToIgnore = [sender stringValue]; | 345 NSString* wordToIgnore = [sender stringValue]; |
| 346 if (wordToIgnore != nil) | 346 if (wordToIgnore != nil) |
| 347 spellcheck_mac::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore)); | 347 spellcheck_mac::IgnoreWord(base::SysNSStringToUTF16(wordToIgnore)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 - (void)showGuessPanel:(id)sender { | 350 - (void)showGuessPanel:(id)sender { |
| 351 render_widget_host_->Send(new SpellCheckMsg_ToggleSpellPanel( | 351 renderWidgetHost_->Send(new SpellCheckMsg_ToggleSpellPanel( |
| 352 render_widget_host_->routing_id(), | 352 renderWidgetHost_->routing_id(), |
| 353 spellcheck_mac::SpellingPanelVisible())); | 353 spellcheck_mac::SpellingPanelVisible())); |
| 354 } | 354 } |
| 355 | 355 |
| 356 - (void)toggleContinuousSpellChecking:(id)sender { | 356 - (void)toggleContinuousSpellChecking:(id)sender { |
| 357 render_widget_host_->Send( | 357 renderWidgetHost_->Send( |
| 358 new SpellCheckMsg_ToggleSpellCheck(render_widget_host_->routing_id())); | 358 new SpellCheckMsg_ToggleSpellCheck(renderWidgetHost_->routing_id())); |
| 359 } | 359 } |
| 360 | 360 |
| 361 - (void)spellCheckEnabled:(BOOL)enabled checked:(BOOL)checked { | 361 - (void)spellCheckEnabled:(BOOL)enabled checked:(BOOL)checked { |
| 362 spellcheck_enabled_ = enabled; | 362 spellcheckEnabled_ = enabled; |
| 363 spellcheck_checked_ = checked; | 363 spellcheckChecked_ = checked; |
| 364 } | 364 } |
| 365 | 365 |
| 366 // END Spellchecking methods | 366 // END Spellchecking methods |
| 367 | 367 |
| 368 @end | 368 @end |
| OLD | NEW |