| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 230 |
| 231 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) | 231 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) |
| 232 : render_widget_host_(widget), | 232 : render_widget_host_(widget), |
| 233 about_to_validate_and_paint_(false), | 233 about_to_validate_and_paint_(false), |
| 234 call_set_needs_display_in_rect_pending_(false), | 234 call_set_needs_display_in_rect_pending_(false), |
| 235 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 235 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 236 spellcheck_enabled_(false), | 236 spellcheck_enabled_(false), |
| 237 spellcheck_checked_(false), | 237 spellcheck_checked_(false), |
| 238 is_loading_(false), | 238 is_loading_(false), |
| 239 is_hidden_(false), | 239 is_hidden_(false), |
| 240 is_showing_context_menu_(false), |
| 240 shutdown_factory_(this), | 241 shutdown_factory_(this), |
| 241 needs_gpu_visibility_update_after_repaint_(false), | 242 needs_gpu_visibility_update_after_repaint_(false), |
| 242 compositing_surface_(gfx::kNullPluginWindow) { | 243 compositing_surface_(gfx::kNullPluginWindow) { |
| 243 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| goes away. | 244 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| goes away. |
| 244 // Since we autorelease it, our caller must put |native_view()| into the view | 245 // Since we autorelease it, our caller must put |native_view()| into the view |
| 245 // hierarchy right after calling us. | 246 // hierarchy right after calling us. |
| 246 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 247 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 247 initWithRenderWidgetHostViewMac:this] autorelease]; | 248 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 248 render_widget_host_->SetView(this); | 249 render_widget_host_->SetView(this); |
| 249 | 250 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 467 } |
| 467 | 468 |
| 468 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { | 469 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { |
| 469 current_cursor_ = cursor; | 470 current_cursor_ = cursor; |
| 470 UpdateCursorIfNecessary(); | 471 UpdateCursorIfNecessary(); |
| 471 } | 472 } |
| 472 | 473 |
| 473 void RenderWidgetHostViewMac::UpdateCursorIfNecessary() { | 474 void RenderWidgetHostViewMac::UpdateCursorIfNecessary() { |
| 474 // Do something special (as Win Chromium does) for arrow cursor while loading | 475 // Do something special (as Win Chromium does) for arrow cursor while loading |
| 475 // a page? TODO(avi): decide | 476 // a page? TODO(avi): decide |
| 477 |
| 478 // Don't update the cursor if a context menu is being shown. |
| 479 if (is_showing_context_menu_) |
| 480 return; |
| 481 |
| 476 // Can we synchronize to the event stream? Switch to -[NSWindow | 482 // Can we synchronize to the event stream? Switch to -[NSWindow |
| 477 // mouseLocationOutsideOfEventStream] if we cannot. TODO(avi): test and see | 483 // mouseLocationOutsideOfEventStream] if we cannot. TODO(avi): test and see |
| 478 NSEvent* event = [[cocoa_view_ window] currentEvent]; | 484 NSEvent* event = [[cocoa_view_ window] currentEvent]; |
| 479 if ([event window] != [cocoa_view_ window]) | 485 if ([event window] != [cocoa_view_ window]) |
| 480 return; | 486 return; |
| 481 | 487 |
| 482 NSCursor* ns_cursor = current_cursor_.GetCursor(); | 488 NSCursor* ns_cursor = current_cursor_.GetCursor(); |
| 483 [ns_cursor set]; | 489 [ns_cursor set]; |
| 484 } | 490 } |
| 485 | 491 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 selected_text_ = text; | 647 selected_text_ = text; |
| 642 [cocoa_view_ setSelectedRange:range.ToNSRange()]; | 648 [cocoa_view_ setSelectedRange:range.ToNSRange()]; |
| 643 // Updaes markedRange when there is no marked text so that retrieving | 649 // Updaes markedRange when there is no marked text so that retrieving |
| 644 // markedRange immediately after calling setMarkdText: returns the current | 650 // markedRange immediately after calling setMarkdText: returns the current |
| 645 // caret position. | 651 // caret position. |
| 646 if (![cocoa_view_ hasMarkedText]) { | 652 if (![cocoa_view_ hasMarkedText]) { |
| 647 [cocoa_view_ setMarkedRange:range.ToNSRange()]; | 653 [cocoa_view_ setMarkedRange:range.ToNSRange()]; |
| 648 } | 654 } |
| 649 } | 655 } |
| 650 | 656 |
| 657 void RenderWidgetHostViewMac::ShowingContextMenu(bool showing) { |
| 658 DCHECK_NE(is_showing_context_menu_, showing); |
| 659 is_showing_context_menu_ = showing; |
| 660 |
| 661 // Create a fake mouse event to inform the render widget that the mouse |
| 662 // left or entered. |
| 663 NSWindow* window = [cocoa_view_ window]; |
| 664 // TODO(asvitkine): If the location outside of the event stream doesn't |
| 665 // correspond to the current event (due to delayed event processing), then |
| 666 // this may result in a cursor flicker if there are later mouse move events |
| 667 // in the pipeline. Find a way to use the mouse location from the event that |
| 668 // dismissed the context menu. |
| 669 NSPoint location = [window mouseLocationOutsideOfEventStream]; |
| 670 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved |
| 671 location:location |
| 672 modifierFlags:0 |
| 673 timestamp:0 |
| 674 windowNumber:[window windowNumber] |
| 675 context:nil |
| 676 eventNumber:0 |
| 677 clickCount:0 |
| 678 pressure:0]; |
| 679 WebMouseEvent web_event = |
| 680 WebInputEventFactory::mouseEvent(event, cocoa_view_); |
| 681 if (showing) |
| 682 web_event.type = WebInputEvent::MouseLeave; |
| 683 render_widget_host_->ForwardMouseEvent(web_event); |
| 684 } |
| 685 |
| 651 bool RenderWidgetHostViewMac::IsPopup() const { | 686 bool RenderWidgetHostViewMac::IsPopup() const { |
| 652 return popup_type_ != WebKit::WebPopupTypeNone; | 687 return popup_type_ != WebKit::WebPopupTypeNone; |
| 653 } | 688 } |
| 654 | 689 |
| 655 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( | 690 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( |
| 656 const gfx::Size& size) { | 691 const gfx::Size& size) { |
| 657 return new BackingStoreMac(render_widget_host_, size); | 692 return new BackingStoreMac(render_widget_host_, size); |
| 658 } | 693 } |
| 659 | 694 |
| 660 // Sets whether or not to accept first responder status. | 695 // Sets whether or not to accept first responder status. |
| (...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2587 if (!string) return NO; | 2622 if (!string) return NO; |
| 2588 | 2623 |
| 2589 // If the user is currently using an IME, confirm the IME input, | 2624 // If the user is currently using an IME, confirm the IME input, |
| 2590 // and then insert the text from the service, the same as TextEdit and Safari. | 2625 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2591 [self confirmComposition]; | 2626 [self confirmComposition]; |
| 2592 [self insertText:string]; | 2627 [self insertText:string]; |
| 2593 return YES; | 2628 return YES; |
| 2594 } | 2629 } |
| 2595 | 2630 |
| 2596 @end | 2631 @end |
| OLD | NEW |