| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" | 7 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); | 39 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); |
| 40 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); | 40 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); |
| 41 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); | 41 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); |
| 42 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); | 42 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); |
| 43 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); | 43 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); |
| 44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); | 44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); |
| 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); | 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); |
| 46 | 46 |
| 47 @interface TabContentsViewCocoa (Private) | 47 @interface TabContentsViewCocoa (Private) |
| 48 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; | 48 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; |
| 49 - (void)processKeyboardEvent:(NativeWebKeyboardEvent*)event; | 49 - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)event; |
| 50 - (void)registerDragTypes; | 50 - (void)registerDragTypes; |
| 51 - (void)setCurrentDragOperation:(NSDragOperation)operation; | 51 - (void)setCurrentDragOperation:(NSDragOperation)operation; |
| 52 - (void)startDragWithDropData:(const WebDropData&)dropData | 52 - (void)startDragWithDropData:(const WebDropData&)dropData |
| 53 dragOperationMask:(NSDragOperation)operationMask; | 53 dragOperationMask:(NSDragOperation)operationMask; |
| 54 @end | 54 @end |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 57 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
| 58 return new TabContentsViewMac(tab_contents); | 58 return new TabContentsViewMac(tab_contents); |
| 59 } | 59 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // This is called when we the renderer asks us to take focus back (i.e., it has | 205 // This is called when we the renderer asks us to take focus back (i.e., it has |
| 206 // iterated past the last focusable element on the page). | 206 // iterated past the last focusable element on the page). |
| 207 void TabContentsViewMac::TakeFocus(bool reverse) { | 207 void TabContentsViewMac::TakeFocus(bool reverse) { |
| 208 if (reverse) { | 208 if (reverse) { |
| 209 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; | 209 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; |
| 210 } else { | 210 } else { |
| 211 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; | 211 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 void TabContentsViewMac::HandleKeyboardEvent( | 215 bool TabContentsViewMac::HandleKeyboardEvent( |
| 216 const NativeWebKeyboardEvent& event) { | 216 const NativeWebKeyboardEvent& event) { |
| 217 [cocoa_view_.get() processKeyboardEvent: | 217 return [cocoa_view_.get() processKeyboardEvent: |
| 218 const_cast<NativeWebKeyboardEvent*>(&event)]; | 218 const_cast<NativeWebKeyboardEvent*>(&event)] == YES; |
| 219 } | 219 } |
| 220 | 220 |
| 221 void TabContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { | 221 void TabContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { |
| 222 RenderViewContextMenuMac menu(tab_contents(), | 222 RenderViewContextMenuMac menu(tab_contents(), |
| 223 params, | 223 params, |
| 224 GetNativeView()); | 224 GetNativeView()); |
| 225 menu.Init(); | 225 menu.Init(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 RenderWidgetHostView* TabContentsViewMac::CreateNewWidgetInternal( | 228 RenderWidgetHostView* TabContentsViewMac::CreateNewWidgetInternal( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 303 } |
| 304 | 304 |
| 305 - (void)setCurrentDragOperation:(NSDragOperation)operation { | 305 - (void)setCurrentDragOperation:(NSDragOperation)operation { |
| 306 [dropTarget_ setCurrentOperation:operation]; | 306 [dropTarget_ setCurrentOperation:operation]; |
| 307 } | 307 } |
| 308 | 308 |
| 309 - (TabContents*)tabContents { | 309 - (TabContents*)tabContents { |
| 310 return tabContentsView_->tab_contents(); | 310 return tabContentsView_->tab_contents(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 - (void)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent { | 313 - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent { |
| 314 if (wkEvent->skip_in_browser) | 314 if (wkEvent->skip_in_browser) |
| 315 return; | 315 return NO; |
| 316 | 316 |
| 317 NSEvent* event = wkEvent->os_event; | 317 NSEvent* event = wkEvent->os_event; |
| 318 | 318 |
| 319 if (!event) { | 319 if (!event) { |
| 320 // Char events are synthesized and do not contain a real event. We are not | 320 // Char events are synthesized and do not contain a real event. We are not |
| 321 // interested in them anyway. | 321 // interested in them anyway. |
| 322 DCHECK(wkEvent->type == WebKit::WebInputEvent::Char); | 322 DCHECK(wkEvent->type == WebKit::WebInputEvent::Char); |
| 323 return; | 323 return NO; |
| 324 } | 324 } |
| 325 | 325 |
| 326 // If this tab is no longer active, its window will be |nil|. In that case, | 326 // If this tab is no longer active, its window will be |nil|. In that case, |
| 327 // best ignore the event. | 327 // best ignore the event. |
| 328 if (![self window]) | 328 if (![self window]) |
| 329 return; | 329 return NO; |
| 330 ChromeEventProcessingWindow* window = | 330 ChromeEventProcessingWindow* window = |
| 331 (ChromeEventProcessingWindow*)[self window]; | 331 (ChromeEventProcessingWindow*)[self window]; |
| 332 DCHECK([window isKindOfClass:[ChromeEventProcessingWindow class]]); | 332 DCHECK([window isKindOfClass:[ChromeEventProcessingWindow class]]); |
| 333 | 333 |
| 334 // Do not fire shortcuts on key up. | 334 // Do not fire shortcuts on key up. |
| 335 if ([event type] == NSKeyDown) { | 335 if ([event type] == NSKeyDown) { |
| 336 if ([window handleExtraBrowserKeyboardShortcut:event]) | 336 if ([window handleExtraBrowserKeyboardShortcut:event]) |
| 337 return; | 337 return YES; |
| 338 if ([window handleExtraWindowKeyboardShortcut:event]) | 338 if ([window handleExtraWindowKeyboardShortcut:event]) |
| 339 return; | 339 return YES; |
| 340 } | 340 } |
| 341 | 341 |
| 342 // We need to re-dispatch the event, so that it is sent to the menu or other | 342 // We need to re-dispatch the event, so that it is sent to the menu or other |
| 343 // cocoa mechanisms (such as the cmd-` handler). | 343 // cocoa mechanisms (such as the cmd-` handler). |
| 344 RenderWidgetHostViewCocoa* rwhv = static_cast<RenderWidgetHostViewCocoa*>( | 344 RenderWidgetHostViewCocoa* rwhv = static_cast<RenderWidgetHostViewCocoa*>( |
| 345 tabContentsView_->GetContentNativeView()); | 345 tabContentsView_->GetContentNativeView()); |
| 346 DCHECK([rwhv isKindOfClass:[RenderWidgetHostViewCocoa class]]); | 346 DCHECK([rwhv isKindOfClass:[RenderWidgetHostViewCocoa class]]); |
| 347 [rwhv setIgnoreKeyEvents:YES]; | 347 [rwhv setIgnoreKeyEvents:YES]; |
| 348 [window redispatchEvent:event]; | 348 BOOL eventHandled = [window redispatchEvent:event]; |
| 349 [rwhv setIgnoreKeyEvents:NO]; | 349 [rwhv setIgnoreKeyEvents:NO]; |
| 350 return eventHandled; |
| 350 } | 351 } |
| 351 | 352 |
| 352 - (void)mouseEvent:(NSEvent *)theEvent { | 353 - (void)mouseEvent:(NSEvent *)theEvent { |
| 353 TabContents* tabContents = [self tabContents]; | 354 TabContents* tabContents = [self tabContents]; |
| 354 if (tabContents->delegate()) { | 355 if (tabContents->delegate()) { |
| 355 if ([theEvent type] == NSMouseMoved) | 356 if ([theEvent type] == NSMouseMoved) |
| 356 tabContents->delegate()->ContentsMouseEvent(tabContents, true); | 357 tabContents->delegate()->ContentsMouseEvent(tabContents, true); |
| 357 if ([theEvent type] == NSMouseExited) | 358 if ([theEvent type] == NSMouseExited) |
| 358 tabContents->delegate()->ContentsMouseEvent(tabContents, false); | 359 tabContents->delegate()->ContentsMouseEvent(tabContents, false); |
| 359 } | 360 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 455 } |
| 455 | 456 |
| 456 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 457 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 457 return [dropTarget_ performDragOperation:sender view:self]; | 458 return [dropTarget_ performDragOperation:sender view:self]; |
| 458 } | 459 } |
| 459 | 460 |
| 460 // Tons of stuff goes here, where we grab events going on in Cocoaland and send | 461 // Tons of stuff goes here, where we grab events going on in Cocoaland and send |
| 461 // them into the C++ system. TODO(avi): all that jazz | 462 // them into the C++ system. TODO(avi): all that jazz |
| 462 | 463 |
| 463 @end | 464 @end |
| OLD | NEW |