Chromium Code Reviews| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 // | 641 // |
| 636 // RenderWidgetHostViewCocoa uses the stored selection text, | 642 // RenderWidgetHostViewCocoa uses the stored selection text, |
| 637 // which implements NSServicesRequests protocol. | 643 // which implements NSServicesRequests protocol. |
| 638 // | 644 // |
| 639 void RenderWidgetHostViewMac::SelectionChanged(const std::string& text, | 645 void RenderWidgetHostViewMac::SelectionChanged(const std::string& text, |
| 640 const ui::Range& range) { | 646 const ui::Range& range) { |
| 641 selected_text_ = text; | 647 selected_text_ = text; |
| 642 [cocoa_view_ setSelectedRange:range.ToNSRange()]; | 648 [cocoa_view_ setSelectedRange:range.ToNSRange()]; |
| 643 } | 649 } |
| 644 | 650 |
| 651 void RenderWidgetHostViewMac::ShowingContextMenu(bool showing) { | |
| 652 DCHECK_NE(is_showing_context_menu_, showing); | |
| 653 is_showing_context_menu_ = showing; | |
| 654 | |
| 655 // Create a fake mouse event to inform the render widget that the mouse | |
| 656 // left or entered. | |
| 657 NSWindow* window = [cocoa_view_ window]; | |
| 658 NSPoint location = [window mouseLocationOutsideOfEventStream]; | |
|
Mark Mentovai
2011/07/12 14:06:57
“outside of event stream”—is this a good idea? Wha
| |
| 659 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved | |
| 660 location:location | |
| 661 modifierFlags:0 | |
| 662 timestamp:0 | |
| 663 windowNumber:[window windowNumber] | |
| 664 context:nil | |
| 665 eventNumber:0 | |
| 666 clickCount:0 | |
| 667 pressure:0]; | |
| 668 WebMouseEvent web_event = | |
| 669 WebInputEventFactory::mouseEvent(event, cocoa_view_); | |
| 670 if (showing) | |
| 671 web_event.type = WebInputEvent::MouseLeave; | |
| 672 render_widget_host_->ForwardMouseEvent(web_event); | |
| 673 } | |
| 674 | |
| 645 bool RenderWidgetHostViewMac::IsPopup() const { | 675 bool RenderWidgetHostViewMac::IsPopup() const { |
| 646 return popup_type_ != WebKit::WebPopupTypeNone; | 676 return popup_type_ != WebKit::WebPopupTypeNone; |
| 647 } | 677 } |
| 648 | 678 |
| 649 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( | 679 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( |
| 650 const gfx::Size& size) { | 680 const gfx::Size& size) { |
| 651 return new BackingStoreMac(render_widget_host_, size); | 681 return new BackingStoreMac(render_widget_host_, size); |
| 652 } | 682 } |
| 653 | 683 |
| 654 // Sets whether or not to accept first responder status. | 684 // Sets whether or not to accept first responder status. |
| (...skipping 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2589 if (!string) return NO; | 2619 if (!string) return NO; |
| 2590 | 2620 |
| 2591 // If the user is currently using an IME, confirm the IME input, | 2621 // If the user is currently using an IME, confirm the IME input, |
| 2592 // and then insert the text from the service, the same as TextEdit and Safari. | 2622 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2593 [self confirmComposition]; | 2623 [self confirmComposition]; |
| 2594 [self insertText:string]; | 2624 [self insertText:string]; |
| 2595 return YES; | 2625 return YES; |
| 2596 } | 2626 } |
| 2597 | 2627 |
| 2598 @end | 2628 @end |
| OLD | NEW |