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 29 matching lines...) Expand all Loading... |
40 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); | 40 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); |
41 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); | 41 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); |
42 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); | 42 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); |
43 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); | 43 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); |
44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); | 44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); |
45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); | 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); |
46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); | 46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); |
47 | 47 |
48 @interface TabContentsViewCocoa (Private) | 48 @interface TabContentsViewCocoa (Private) |
49 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; | 49 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; |
50 - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)event; | |
51 - (void)registerDragTypes; | 50 - (void)registerDragTypes; |
52 - (void)setCurrentDragOperation:(NSDragOperation)operation; | 51 - (void)setCurrentDragOperation:(NSDragOperation)operation; |
53 - (void)startDragWithDropData:(const WebDropData&)dropData | 52 - (void)startDragWithDropData:(const WebDropData&)dropData |
54 dragOperationMask:(NSDragOperation)operationMask; | 53 dragOperationMask:(NSDragOperation)operationMask; |
55 - (void)cancelDeferredClose; | 54 - (void)cancelDeferredClose; |
56 - (void)closeTabAfterEvent; | 55 - (void)closeTabAfterEvent; |
57 @end | 56 @end |
58 | 57 |
59 // static | 58 // static |
60 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 59 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // This is called when we the renderer asks us to take focus back (i.e., it has | 223 // This is called when we the renderer asks us to take focus back (i.e., it has |
225 // iterated past the last focusable element on the page). | 224 // iterated past the last focusable element on the page). |
226 void TabContentsViewMac::TakeFocus(bool reverse) { | 225 void TabContentsViewMac::TakeFocus(bool reverse) { |
227 if (reverse) { | 226 if (reverse) { |
228 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; | 227 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; |
229 } else { | 228 } else { |
230 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; | 229 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; |
231 } | 230 } |
232 } | 231 } |
233 | 232 |
234 bool TabContentsViewMac::HandleKeyboardEvent( | |
235 const NativeWebKeyboardEvent& event) { | |
236 return [cocoa_view_.get() processKeyboardEvent: | |
237 const_cast<NativeWebKeyboardEvent*>(&event)] == YES; | |
238 } | |
239 | |
240 void TabContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { | 233 void TabContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { |
241 RenderViewContextMenuMac menu(tab_contents(), | 234 RenderViewContextMenuMac menu(tab_contents(), |
242 params, | 235 params, |
243 GetNativeView()); | 236 GetNativeView()); |
244 menu.Init(); | 237 menu.Init(); |
245 } | 238 } |
246 | 239 |
247 RenderWidgetHostView* TabContentsViewMac::CreateNewWidgetInternal( | 240 RenderWidgetHostView* TabContentsViewMac::CreateNewWidgetInternal( |
248 int route_id, | 241 int route_id, |
249 bool activatable) { | 242 bool activatable) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 341 } |
349 | 342 |
350 - (void)setCurrentDragOperation:(NSDragOperation)operation { | 343 - (void)setCurrentDragOperation:(NSDragOperation)operation { |
351 [dropTarget_ setCurrentOperation:operation]; | 344 [dropTarget_ setCurrentOperation:operation]; |
352 } | 345 } |
353 | 346 |
354 - (TabContents*)tabContents { | 347 - (TabContents*)tabContents { |
355 return tabContentsView_->tab_contents(); | 348 return tabContentsView_->tab_contents(); |
356 } | 349 } |
357 | 350 |
358 - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent { | |
359 if (wkEvent->skip_in_browser || wkEvent->type == WebKit::WebInputEvent::Char) | |
360 return NO; | |
361 | |
362 NSEvent* event = wkEvent->os_event; | |
363 DCHECK(event != NULL); | |
364 | |
365 // If this tab is no longer active, its window will be |nil|. In that case, | |
366 // best ignore the event. | |
367 if (![self window]) | |
368 return NO; | |
369 ChromeEventProcessingWindow* window = | |
370 (ChromeEventProcessingWindow*)[self window]; | |
371 DCHECK([window isKindOfClass:[ChromeEventProcessingWindow class]]); | |
372 | |
373 // Do not fire shortcuts on key up. | |
374 if ([event type] == NSKeyDown) { | |
375 // Send the event to the menu before sending it to the browser/window | |
376 // shortcut handling, so that if a user configures cmd-left to mean | |
377 // "previous tab", it takes precedence over the built-in "history back" | |
378 // binding. Other than that, the |redispatchEvent| call would take care of | |
379 // invoking the original menu item shortcut as well. | |
380 if ([[NSApp mainMenu] performKeyEquivalent:event]) | |
381 return YES; | |
382 | |
383 if ([window handleExtraBrowserKeyboardShortcut:event]) | |
384 return YES; | |
385 if ([window handleExtraWindowKeyboardShortcut:event]) | |
386 return YES; | |
387 } | |
388 | |
389 // We need to re-dispatch the event, so that it is sent to the menu or other | |
390 // cocoa mechanisms (such as the cmd-` handler). | |
391 RenderWidgetHostViewCocoa* rwhv = static_cast<RenderWidgetHostViewCocoa*>( | |
392 tabContentsView_->GetContentNativeView()); | |
393 DCHECK([rwhv isKindOfClass:[RenderWidgetHostViewCocoa class]]); | |
394 [rwhv setIgnoreKeyEvents:YES]; | |
395 BOOL eventHandled = [window redispatchEvent:event]; | |
396 [rwhv setIgnoreKeyEvents:NO]; | |
397 return eventHandled; | |
398 } | |
399 | |
400 - (void)mouseEvent:(NSEvent *)theEvent { | 351 - (void)mouseEvent:(NSEvent *)theEvent { |
401 TabContents* tabContents = [self tabContents]; | 352 TabContents* tabContents = [self tabContents]; |
402 if (tabContents->delegate()) { | 353 if (tabContents->delegate()) { |
403 NSPoint location = [NSEvent mouseLocation]; | 354 NSPoint location = [NSEvent mouseLocation]; |
404 if ([theEvent type] == NSMouseMoved) | 355 if ([theEvent type] == NSMouseMoved) |
405 tabContents->delegate()->ContentsMouseEvent( | 356 tabContents->delegate()->ContentsMouseEvent( |
406 tabContents, gfx::Point(location.x, location.y), true); | 357 tabContents, gfx::Point(location.x, location.y), true); |
407 if ([theEvent type] == NSMouseExited) | 358 if ([theEvent type] == NSMouseExited) |
408 tabContents->delegate()->ContentsMouseEvent( | 359 tabContents->delegate()->ContentsMouseEvent( |
409 tabContents, gfx::Point(location.x, location.y), false); | 360 tabContents, gfx::Point(location.x, location.y), false); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 479 } |
529 | 480 |
530 - (void)closeTabAfterEvent { | 481 - (void)closeTabAfterEvent { |
531 tabContentsView_->CloseTab(); | 482 tabContentsView_->CloseTab(); |
532 } | 483 } |
533 | 484 |
534 // Tons of stuff goes here, where we grab events going on in Cocoaland and send | 485 // Tons of stuff goes here, where we grab events going on in Cocoaland and send |
535 // them into the C++ system. TODO(avi): all that jazz | 486 // them into the C++ system. TODO(avi): all that jazz |
536 | 487 |
537 @end | 488 @end |
OLD | NEW |