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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 blink::WebScreenInfo* results) { | 476 blink::WebScreenInfo* results) { |
477 *results = GetWebScreenInfo(NULL); | 477 *results = GetWebScreenInfo(NULL); |
478 } | 478 } |
479 | 479 |
480 /////////////////////////////////////////////////////////////////////////////// | 480 /////////////////////////////////////////////////////////////////////////////// |
481 // RenderWidgetHostViewMac, public: | 481 // RenderWidgetHostViewMac, public: |
482 | 482 |
483 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 483 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
484 bool is_guest_view_hack) | 484 bool is_guest_view_hack) |
485 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 485 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
486 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | |
487 can_compose_inline_(true), | |
488 page_at_minimum_scale_(true), | 486 page_at_minimum_scale_(true), |
489 is_loading_(false), | 487 is_loading_(false), |
490 allow_pause_for_resize_or_repaint_(true), | 488 allow_pause_for_resize_or_repaint_(true), |
491 is_guest_view_hack_(is_guest_view_hack), | 489 is_guest_view_hack_(is_guest_view_hack), |
492 fullscreen_parent_host_view_(nullptr), | 490 fullscreen_parent_host_view_(nullptr), |
493 weak_factory_(this) { | 491 weak_factory_(this) { |
494 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 492 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
495 // goes away. Since we autorelease it, our caller must put | 493 // goes away. Since we autorelease it, our caller must put |
496 // |GetNativeView()| into the view hierarchy right after calling us. | 494 // |GetNativeView()| into the view hierarchy right after calling us. |
497 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 495 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
(...skipping 24 matching lines...) Expand all Loading... |
522 ->GetInputEventRouter() | 520 ->GetInputEventRouter() |
523 ->AddSurfaceClientIdOwner(GetSurfaceClientId(), this); | 521 ->AddSurfaceClientIdOwner(GetSurfaceClientId(), this); |
524 } | 522 } |
525 | 523 |
526 RenderViewHost* rvh = RenderViewHost::From(render_widget_host_); | 524 RenderViewHost* rvh = RenderViewHost::From(render_widget_host_); |
527 if (rvh) { | 525 if (rvh) { |
528 // TODO(mostynb): actually use prefs. Landing this as a separate CL | 526 // TODO(mostynb): actually use prefs. Landing this as a separate CL |
529 // first to rebaseline some unreliable layout tests. | 527 // first to rebaseline some unreliable layout tests. |
530 ignore_result(rvh->GetWebkitPreferences()); | 528 ignore_result(rvh->GetWebkitPreferences()); |
531 } | 529 } |
| 530 |
| 531 if (GetTextInputManager()) |
| 532 GetTextInputManager()->AddObserver(this); |
532 } | 533 } |
533 | 534 |
534 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 535 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
535 display::Screen::GetScreen()->RemoveObserver(this); | 536 display::Screen::GetScreen()->RemoveObserver(this); |
536 | 537 |
537 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 538 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
538 // pointer. | 539 // pointer. |
539 cocoa_view_ = nil; | 540 cocoa_view_ = nil; |
540 | 541 |
541 UnlockMouse(); | 542 UnlockMouse(); |
(...skipping 18 matching lines...) Expand all Loading... |
560 } | 561 } |
561 | 562 |
562 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { | 563 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { |
563 allow_pause_for_resize_or_repaint_ = allow; | 564 allow_pause_for_resize_or_repaint_ = allow; |
564 } | 565 } |
565 | 566 |
566 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { | 567 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { |
567 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); | 568 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); |
568 } | 569 } |
569 | 570 |
| 571 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() { |
| 572 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) |
| 573 return ui::TEXT_INPUT_TYPE_NONE; |
| 574 return GetTextInputManager()->GetTextInputState()->type; |
| 575 } |
| 576 |
570 /////////////////////////////////////////////////////////////////////////////// | 577 /////////////////////////////////////////////////////////////////////////////// |
571 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 578 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
572 | 579 |
573 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 580 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
574 bool handled = true; | 581 bool handled = true; |
575 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 582 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
576 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 583 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
577 OnGetRenderedTextCompleted) | 584 OnGetRenderedTextCompleted) |
578 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, | 585 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, |
579 OnSetNeedsBeginFrames) | 586 OnSetNeedsBeginFrames) |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 WebCursor web_cursor = cursor; | 883 WebCursor web_cursor = cursor; |
877 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()]; | 884 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()]; |
878 } | 885 } |
879 | 886 |
880 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { | 887 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { |
881 is_loading_ = is_loading; | 888 is_loading_ = is_loading; |
882 // If we ever decide to show the waiting cursor while the page is loading | 889 // If we ever decide to show the waiting cursor while the page is loading |
883 // like Chrome does on Windows, call |UpdateCursor()| here. | 890 // like Chrome does on Windows, call |UpdateCursor()| here. |
884 } | 891 } |
885 | 892 |
886 void RenderWidgetHostViewMac::TextInputStateChanged( | 893 void RenderWidgetHostViewMac::OnUpdateTextInputStateCalled( |
887 const TextInputState& params) { | 894 TextInputManager* text_input_manager, |
888 if (text_input_type_ != params.type | 895 RenderWidgetHostViewBase* updated_view, |
889 || can_compose_inline_ != params.can_compose_inline) { | 896 bool did_update_state) { |
890 text_input_type_ = params.type; | 897 if (!did_update_state) |
891 can_compose_inline_ = params.can_compose_inline; | 898 return; |
892 if (HasFocus()) { | |
893 SetTextInputActive(true); | |
894 | 899 |
895 // Let AppKit cache the new input context to make IMEs happy. | 900 if (HasFocus()) { |
896 // See http://crbug.com/73039. | 901 SetTextInputActive(true); |
897 [NSApp updateWindows]; | 902 |
| 903 // Let AppKit cache the new input context to make IMEs happy. |
| 904 // See http://crbug.com/73039. |
| 905 [NSApp updateWindows]; |
898 | 906 |
899 #ifndef __LP64__ | 907 #ifndef __LP64__ |
900 UseInputWindow(TSMGetActiveDocument(), !can_compose_inline_); | 908 bool can_compose_inline = |
| 909 !!GetTextInputManager()->GetActiveWidget() |
| 910 ? GetTextInputManager()->GetTextInputState()->can_compose_inline |
| 911 : true; |
| 912 UseInputWindow(TSMGetActiveDocument(), !can_compose_inline); |
901 #endif | 913 #endif |
902 } | |
903 } | 914 } |
904 } | 915 } |
905 | 916 |
906 void RenderWidgetHostViewMac::ImeCancelComposition() { | 917 void RenderWidgetHostViewMac::ImeCancelComposition() { |
907 [cocoa_view_ cancelComposition]; | 918 [cocoa_view_ cancelComposition]; |
908 } | 919 } |
909 | 920 |
910 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( | 921 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( |
911 const gfx::Range& range, | 922 const gfx::Range& range, |
912 const std::vector<gfx::Rect>& character_bounds) { | 923 const std::vector<gfx::Rect>& character_bounds) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 pepper_fullscreen_window_.autorelease(); | 960 pepper_fullscreen_window_.autorelease(); |
950 | 961 |
951 // Delete the delegated frame state, which will reach back into | 962 // Delete the delegated frame state, which will reach back into |
952 // render_widget_host_. | 963 // render_widget_host_. |
953 browser_compositor_.reset(); | 964 browser_compositor_.reset(); |
954 | 965 |
955 // Make sure none of our observers send events for us to process after | 966 // Make sure none of our observers send events for us to process after |
956 // we release render_widget_host_. | 967 // we release render_widget_host_. |
957 NotifyObserversAboutShutdown(); | 968 NotifyObserversAboutShutdown(); |
958 | 969 |
| 970 if (text_input_manager_) |
| 971 text_input_manager_->RemoveObserver(this); |
| 972 |
959 // We get this call just before |render_widget_host_| deletes | 973 // We get this call just before |render_widget_host_| deletes |
960 // itself. But we are owned by |cocoa_view_|, which may be retained | 974 // itself. But we are owned by |cocoa_view_|, which may be retained |
961 // by some other code. Examples are WebContentsViewMac's | 975 // by some other code. Examples are WebContentsViewMac's |
962 // |latent_focus_view_| and TabWindowController's | 976 // |latent_focus_view_| and TabWindowController's |
963 // |cachedContentView_|. | 977 // |cachedContentView_|. |
964 render_widget_host_ = NULL; | 978 render_widget_host_ = NULL; |
965 } | 979 } |
966 | 980 |
967 // Called from the renderer to tell us what the tooltip text should be. It | 981 // Called from the renderer to tell us what the tooltip text should be. It |
968 // calls us frequently so we need to cache the value to prevent doing a lot | 982 // calls us frequently so we need to cache the value to prevent doing a lot |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; | 1554 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
1541 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; | 1555 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
1542 NSPoint originInScreen = | 1556 NSPoint originInScreen = |
1543 ui::ConvertPointFromWindowToScreen([cocoa_view_ window], originInWindow); | 1557 ui::ConvertPointFromWindowToScreen([cocoa_view_ window], originInWindow); |
1544 originInScreen.y = originInScreen.y - size.height; | 1558 originInScreen.y = originInScreen.y - size.height; |
1545 return gfx::Point(originInScreen.x, originInScreen.y); | 1559 return gfx::Point(originInScreen.x, originInScreen.y); |
1546 } | 1560 } |
1547 | 1561 |
1548 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 1562 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
1549 if (active) { | 1563 if (active) { |
1550 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1564 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_PASSWORD) |
1551 EnablePasswordInput(); | 1565 EnablePasswordInput(); |
1552 else | 1566 else |
1553 DisablePasswordInput(); | 1567 DisablePasswordInput(); |
1554 } else { | 1568 } else { |
1555 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1569 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_PASSWORD) |
1556 DisablePasswordInput(); | 1570 DisablePasswordInput(); |
1557 } | 1571 } |
1558 } | 1572 } |
1559 | 1573 |
1560 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( | 1574 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( |
1561 const std::string& text) { | 1575 const std::string& text) { |
1562 SpeakText(text); | 1576 SpeakText(text); |
1563 } | 1577 } |
1564 | 1578 |
1565 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { | 1579 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { |
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2888 } | 2902 } |
2889 | 2903 |
2890 - (NSInteger)conversationIdentifier { | 2904 - (NSInteger)conversationIdentifier { |
2891 return reinterpret_cast<NSInteger>(self); | 2905 return reinterpret_cast<NSInteger>(self); |
2892 } | 2906 } |
2893 | 2907 |
2894 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 2908 // Each RenderWidgetHostViewCocoa has its own input context, but we return |
2895 // nil when the caret is in non-editable content or password box to avoid | 2909 // nil when the caret is in non-editable content or password box to avoid |
2896 // making input methods do their work. | 2910 // making input methods do their work. |
2897 - (NSTextInputContext *)inputContext { | 2911 - (NSTextInputContext *)inputContext { |
2898 switch(renderWidgetHostView_->text_input_type_) { | 2912 switch (renderWidgetHostView_->GetTextInputType()) { |
2899 case ui::TEXT_INPUT_TYPE_NONE: | 2913 case ui::TEXT_INPUT_TYPE_NONE: |
2900 case ui::TEXT_INPUT_TYPE_PASSWORD: | 2914 case ui::TEXT_INPUT_TYPE_PASSWORD: |
2901 return nil; | 2915 return nil; |
2902 default: | 2916 default: |
2903 return [super inputContext]; | 2917 return [super inputContext]; |
2904 } | 2918 } |
2905 } | 2919 } |
2906 | 2920 |
2907 - (BOOL)hasMarkedText { | 2921 - (BOOL)hasMarkedText { |
2908 // An input method calls this function to figure out whether or not an | 2922 // An input method calls this function to figure out whether or not an |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3165 | 3179 |
3166 // Overriding a NSResponder method to support application services. | 3180 // Overriding a NSResponder method to support application services. |
3167 | 3181 |
3168 - (id)validRequestorForSendType:(NSString*)sendType | 3182 - (id)validRequestorForSendType:(NSString*)sendType |
3169 returnType:(NSString*)returnType { | 3183 returnType:(NSString*)returnType { |
3170 id requestor = nil; | 3184 id requestor = nil; |
3171 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; | 3185 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; |
3172 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; | 3186 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; |
3173 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); | 3187 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); |
3174 BOOL takesText = | 3188 BOOL takesText = |
3175 renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; | 3189 renderWidgetHostView_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
3176 | 3190 |
3177 if (sendTypeIsString && hasText && !returnType) { | 3191 if (sendTypeIsString && hasText && !returnType) { |
3178 requestor = self; | 3192 requestor = self; |
3179 } else if (!sendType && returnTypeIsString && takesText) { | 3193 } else if (!sendType && returnTypeIsString && takesText) { |
3180 requestor = self; | 3194 requestor = self; |
3181 } else if (sendTypeIsString && returnTypeIsString && hasText && takesText) { | 3195 } else if (sendTypeIsString && returnTypeIsString && hasText && takesText) { |
3182 requestor = self; | 3196 requestor = self; |
3183 } else { | 3197 } else { |
3184 requestor = [super validRequestorForSendType:sendType | 3198 requestor = [super validRequestorForSendType:sendType |
3185 returnType:returnType]; | 3199 returnType:returnType]; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3235 | 3249 |
3236 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3250 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3237 // regions that are not draggable. (See ControlRegionView in | 3251 // regions that are not draggable. (See ControlRegionView in |
3238 // native_app_window_cocoa.mm). This requires the render host view to be | 3252 // native_app_window_cocoa.mm). This requires the render host view to be |
3239 // draggable by default. | 3253 // draggable by default. |
3240 - (BOOL)mouseDownCanMoveWindow { | 3254 - (BOOL)mouseDownCanMoveWindow { |
3241 return YES; | 3255 return YES; |
3242 } | 3256 } |
3243 | 3257 |
3244 @end | 3258 @end |
OLD | NEW |