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 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 blink::WebScreenInfo* results) { | 506 blink::WebScreenInfo* results) { |
507 *results = GetWebScreenInfo(NULL); | 507 *results = GetWebScreenInfo(NULL); |
508 } | 508 } |
509 | 509 |
510 /////////////////////////////////////////////////////////////////////////////// | 510 /////////////////////////////////////////////////////////////////////////////// |
511 // RenderWidgetHostViewMac, public: | 511 // RenderWidgetHostViewMac, public: |
512 | 512 |
513 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 513 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
514 bool is_guest_view_hack) | 514 bool is_guest_view_hack) |
515 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 515 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
516 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | |
517 can_compose_inline_(true), | |
518 browser_compositor_state_(BrowserCompositorDestroyed), | 516 browser_compositor_state_(BrowserCompositorDestroyed), |
519 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder), | 517 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder), |
520 page_at_minimum_scale_(true), | 518 page_at_minimum_scale_(true), |
521 is_loading_(false), | 519 is_loading_(false), |
522 allow_pause_for_resize_or_repaint_(true), | 520 allow_pause_for_resize_or_repaint_(true), |
523 is_guest_view_hack_(is_guest_view_hack), | 521 is_guest_view_hack_(is_guest_view_hack), |
524 fullscreen_parent_host_view_(NULL), | 522 fullscreen_parent_host_view_(NULL), |
525 weak_factory_(this) { | 523 weak_factory_(this) { |
526 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 524 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
527 // goes away. Since we autorelease it, our caller must put | 525 // goes away. Since we autorelease it, our caller must put |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 WebCursor web_cursor = cursor; | 1006 WebCursor web_cursor = cursor; |
1009 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()]; | 1007 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()]; |
1010 } | 1008 } |
1011 | 1009 |
1012 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { | 1010 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { |
1013 is_loading_ = is_loading; | 1011 is_loading_ = is_loading; |
1014 // If we ever decide to show the waiting cursor while the page is loading | 1012 // If we ever decide to show the waiting cursor while the page is loading |
1015 // like Chrome does on Windows, call |UpdateCursor()| here. | 1013 // like Chrome does on Windows, call |UpdateCursor()| here. |
1016 } | 1014 } |
1017 | 1015 |
1018 void RenderWidgetHostViewMac::TextInputStateChanged( | 1016 void RenderWidgetHostViewMac::UpdateTextInputState() { |
1019 const ViewHostMsg_TextInputState_Params& params) { | 1017 RenderWidgetHostViewBase* focused_view = GetFocusedView(); |
1020 if (text_input_type_ != params.type | 1018 if (!focused_view->ShouldProcessTextInputState()) |
1021 || can_compose_inline_ != params.can_compose_inline) { | 1019 return; |
1022 text_input_type_ = params.type; | |
1023 can_compose_inline_ = params.can_compose_inline; | |
1024 if (HasFocus()) { | |
1025 SetTextInputActive(true); | |
1026 | 1020 |
1027 // Let AppKit cache the new input context to make IMEs happy. | 1021 cached_text_input_state_ = focused_view->text_input_state(); |
1028 // See http://crbug.com/73039. | 1022 |
1029 [NSApp updateWindows]; | 1023 if (HasFocus()) { |
| 1024 SetTextInputActive(true); |
| 1025 |
| 1026 // Let AppKit cache the new input context to make IMEs happy. |
| 1027 // See http://crbug.com/73039. |
| 1028 [NSApp updateWindows]; |
1030 | 1029 |
1031 #ifndef __LP64__ | 1030 #ifndef __LP64__ |
1032 UseInputWindow(TSMGetActiveDocument(), !can_compose_inline_); | 1031 UseInputWindow(TSMGetActiveDocument(), |
| 1032 focused_view->text_input_state() _->can_compose_inline_); |
1033 #endif | 1033 #endif |
1034 } | |
1035 } | 1034 } |
1036 } | 1035 } |
1037 | 1036 |
1038 void RenderWidgetHostViewMac::ImeCancelComposition() { | 1037 void RenderWidgetHostViewMac::ImeCancelComposition() { |
1039 [cocoa_view_ cancelComposition]; | 1038 [cocoa_view_ cancelComposition]; |
1040 } | 1039 } |
1041 | 1040 |
1042 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( | 1041 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( |
1043 const gfx::Range& range, | 1042 const gfx::Range& range, |
1044 const std::vector<gfx::Rect>& character_bounds) { | 1043 const std::vector<gfx::Rect>& character_bounds) { |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; | 1708 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
1710 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; | 1709 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
1711 NSPoint originInScreen = | 1710 NSPoint originInScreen = |
1712 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; | 1711 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; |
1713 originInScreen.y = originInScreen.y - size.height; | 1712 originInScreen.y = originInScreen.y - size.height; |
1714 return gfx::Point(originInScreen.x, originInScreen.y); | 1713 return gfx::Point(originInScreen.x, originInScreen.y); |
1715 } | 1714 } |
1716 | 1715 |
1717 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 1716 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
1718 if (active) { | 1717 if (active) { |
1719 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1718 if (current_text_input_state()->type == ui::TEXT_INPUT_TYPE_PASSWORD) |
1720 EnablePasswordInput(); | 1719 EnablePasswordInput(); |
1721 else | 1720 else |
1722 DisablePasswordInput(); | 1721 DisablePasswordInput(); |
1723 } else { | 1722 } else { |
1724 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1723 if (current_text_input_state()->type == ui::TEXT_INPUT_TYPE_PASSWORD) |
1725 DisablePasswordInput(); | 1724 DisablePasswordInput(); |
1726 } | 1725 } |
1727 } | 1726 } |
1728 | 1727 |
1729 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, | 1728 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, |
1730 int plugin_id) { | 1729 int plugin_id) { |
1731 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; | 1730 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; |
1732 } | 1731 } |
1733 | 1732 |
1734 void RenderWidgetHostViewMac::OnStartPluginIme() { | 1733 void RenderWidgetHostViewMac::OnStartPluginIme() { |
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3069 return reinterpret_cast<NSInteger>(self); | 3068 return reinterpret_cast<NSInteger>(self); |
3070 } | 3069 } |
3071 | 3070 |
3072 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 3071 // Each RenderWidgetHostViewCocoa has its own input context, but we return |
3073 // nil when the caret is in non-editable content or password box to avoid | 3072 // nil when the caret is in non-editable content or password box to avoid |
3074 // making input methods do their work. | 3073 // making input methods do their work. |
3075 - (NSTextInputContext *)inputContext { | 3074 - (NSTextInputContext *)inputContext { |
3076 if (focusedPluginIdentifier_ != -1) | 3075 if (focusedPluginIdentifier_ != -1) |
3077 return [[ComplexTextInputPanel sharedComplexTextInputPanel] inputContext]; | 3076 return [[ComplexTextInputPanel sharedComplexTextInputPanel] inputContext]; |
3078 | 3077 |
3079 switch(renderWidgetHostView_->text_input_type_) { | 3078 switch (renderWidgetHostView_->current_text_input_state()->type) { |
3080 case ui::TEXT_INPUT_TYPE_NONE: | 3079 case ui::TEXT_INPUT_TYPE_NONE: |
3081 case ui::TEXT_INPUT_TYPE_PASSWORD: | 3080 case ui::TEXT_INPUT_TYPE_PASSWORD: |
3082 return nil; | 3081 return nil; |
3083 default: | 3082 default: |
3084 return [super inputContext]; | 3083 return [super inputContext]; |
3085 } | 3084 } |
3086 } | 3085 } |
3087 | 3086 |
3088 - (BOOL)hasMarkedText { | 3087 - (BOOL)hasMarkedText { |
3089 // An input method calls this function to figure out whether or not an | 3088 // An input method calls this function to figure out whether or not an |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3404 } | 3403 } |
3405 | 3404 |
3406 // Overriding a NSResponder method to support application services. | 3405 // Overriding a NSResponder method to support application services. |
3407 | 3406 |
3408 - (id)validRequestorForSendType:(NSString*)sendType | 3407 - (id)validRequestorForSendType:(NSString*)sendType |
3409 returnType:(NSString*)returnType { | 3408 returnType:(NSString*)returnType { |
3410 id requestor = nil; | 3409 id requestor = nil; |
3411 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; | 3410 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; |
3412 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; | 3411 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; |
3413 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); | 3412 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); |
3414 BOOL takesText = | 3413 BOOL takesText = renderWidgetHostView_->current_text_input_state()->type != |
3415 renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; | 3414 ui::TEXT_INPUT_TYPE_NONE; |
3416 | 3415 |
3417 if (sendTypeIsString && hasText && !returnType) { | 3416 if (sendTypeIsString && hasText && !returnType) { |
3418 requestor = self; | 3417 requestor = self; |
3419 } else if (!sendType && returnTypeIsString && takesText) { | 3418 } else if (!sendType && returnTypeIsString && takesText) { |
3420 requestor = self; | 3419 requestor = self; |
3421 } else if (sendTypeIsString && returnTypeIsString && hasText && takesText) { | 3420 } else if (sendTypeIsString && returnTypeIsString && hasText && takesText) { |
3422 requestor = self; | 3421 requestor = self; |
3423 } else { | 3422 } else { |
3424 requestor = [super validRequestorForSendType:sendType | 3423 requestor = [super validRequestorForSendType:sendType |
3425 returnType:returnType]; | 3424 returnType:returnType]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3489 | 3488 |
3490 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3489 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3491 // regions that are not draggable. (See ControlRegionView in | 3490 // regions that are not draggable. (See ControlRegionView in |
3492 // native_app_window_cocoa.mm). This requires the render host view to be | 3491 // native_app_window_cocoa.mm). This requires the render host view to be |
3493 // draggable by default. | 3492 // draggable by default. |
3494 - (BOOL)mouseDownCanMoveWindow { | 3493 - (BOOL)mouseDownCanMoveWindow { |
3495 return YES; | 3494 return YES; |
3496 } | 3495 } |
3497 | 3496 |
3498 @end | 3497 @end |
OLD | NEW |