Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2229223002: Route IME-related IPCs to the active/focused RenderWidget (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 546 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the
547 // RenderWidgetHost does we need to tell it not to hold a stale pointer to 547 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
548 // us. 548 // us.
549 if (render_widget_host_) { 549 if (render_widget_host_) {
550 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the 550 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the
551 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's 551 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's
552 // view, the RenderWidgetHostViewGuest will do it. 552 // view, the RenderWidgetHostViewGuest will do it.
553 if (!is_guest_view_hack_) 553 if (!is_guest_view_hack_)
554 render_widget_host_->SetView(NULL); 554 render_widget_host_->SetView(NULL);
555 } 555 }
556
557 // In case the view is deleted (by cocoa view) before calling destroy, we need
558 // to remove this view from the observer list of TextInputManager.
559 if (text_input_manager_ && text_input_manager_->HasObserver(this))
560 text_input_manager_->RemoveObserver(this);
556 } 561 }
557 562
558 void RenderWidgetHostViewMac::SetDelegate( 563 void RenderWidgetHostViewMac::SetDelegate(
559 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { 564 NSObject<RenderWidgetHostViewMacDelegate>* delegate) {
560 [cocoa_view_ setResponderDelegate:delegate]; 565 [cocoa_view_ setResponderDelegate:delegate];
561 } 566 }
562 567
563 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { 568 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) {
564 allow_pause_for_resize_or_repaint_ = allow; 569 allow_pause_for_resize_or_repaint_ = allow;
565 } 570 }
566 571
567 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { 572 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const {
568 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); 573 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting();
569 } 574 }
570 575
571 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() { 576 ui::TextInputType RenderWidgetHostViewMac::GetTextInputType() {
572 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget()) 577 if (!GetTextInputManager() || !GetTextInputManager()->GetActiveWidget())
573 return ui::TEXT_INPUT_TYPE_NONE; 578 return ui::TEXT_INPUT_TYPE_NONE;
574 return GetTextInputManager()->GetTextInputState()->type; 579 return GetTextInputManager()->GetTextInputState()->type;
575 } 580 }
576 581
582 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() {
583 return !!GetTextInputManager() ? GetTextInputManager()->GetActiveWidget()
Avi (use Gerrit) 2016/08/10 21:01:40 You shouldn't need the !!.
EhsanK 2016/08/10 21:27:28 Acknowledged.
584 : nullptr;
585 }
586
577 /////////////////////////////////////////////////////////////////////////////// 587 ///////////////////////////////////////////////////////////////////////////////
578 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: 588 // RenderWidgetHostViewMac, RenderWidgetHostView implementation:
579 589
580 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 590 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
581 bool handled = true; 591 bool handled = true;
582 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 592 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
583 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, 593 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted,
584 OnGetRenderedTextCompleted) 594 OnGetRenderedTextCompleted)
585 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, 595 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames,
586 OnSetNeedsBeginFrames) 596 OnSetNeedsBeginFrames)
(...skipping 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 // text when it cancels an ongoing composition, i.e. I have never seen an 2953 // text when it cancels an ongoing composition, i.e. I have never seen an
2944 // input method calls this method. 2954 // input method calls this method.
2945 hasMarkedText_ = NO; 2955 hasMarkedText_ = NO;
2946 markedText_.clear(); 2956 markedText_.clear();
2947 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); 2957 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0);
2948 underlines_.clear(); 2958 underlines_.clear();
2949 2959
2950 // If we are handling a key down event, then ConfirmComposition() will be 2960 // If we are handling a key down event, then ConfirmComposition() will be
2951 // called in keyEvent: method. 2961 // called in keyEvent: method.
2952 if (!handlingKeyDown_) { 2962 if (!handlingKeyDown_) {
2953 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 2963 if (renderWidgetHostView_->GetActiveWidget()) {
2954 base::string16(), gfx::Range::InvalidRange(), false); 2964 renderWidgetHostView_->GetActiveWidget()->ImeConfirmComposition(
2965 base::string16(), gfx::Range::InvalidRange(), false);
2966 }
2955 } else { 2967 } else {
2956 unmarkTextCalled_ = YES; 2968 unmarkTextCalled_ = YES;
2957 } 2969 }
2958 } 2970 }
2959 2971
2960 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange 2972 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange
2961 replacementRange:(NSRange)replacementRange { 2973 replacementRange:(NSRange)replacementRange {
2962 // An input method updates the composition string. 2974 // An input method updates the composition string.
2963 // We send the given text and range to the renderer so it can update the 2975 // We send the given text and range to the renderer so it can update the
2964 // composition node of WebKit. 2976 // composition node of WebKit.
(...skipping 14 matching lines...) Expand all
2979 } else { 2991 } else {
2980 // Use a thin black underline by default. 2992 // Use a thin black underline by default.
2981 underlines_.push_back(blink::WebCompositionUnderline( 2993 underlines_.push_back(blink::WebCompositionUnderline(
2982 0, length, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); 2994 0, length, SK_ColorBLACK, false, SK_ColorTRANSPARENT));
2983 } 2995 }
2984 2996
2985 // If we are handling a key down event, then SetComposition() will be 2997 // If we are handling a key down event, then SetComposition() will be
2986 // called in keyEvent: method. 2998 // called in keyEvent: method.
2987 // Input methods of Mac use setMarkedText calls with an empty text to cancel 2999 // Input methods of Mac use setMarkedText calls with an empty text to cancel
2988 // an ongoing composition. So, we should check whether or not the given text 3000 // an ongoing composition. So, we should check whether or not the given text
2989 // is empty to update the input method state. (Our input method backend can 3001 // is empty to update the input method state. (Our input method backend
2990 // automatically cancels an ongoing composition when we send an empty text. 3002 // automatically cancels an ongoing composition when we send an empty text.
2991 // So, it is OK to send an empty text to the renderer.) 3003 // So, it is OK to send an empty text to the renderer.)
2992 if (handlingKeyDown_) { 3004 if (handlingKeyDown_) {
2993 setMarkedTextReplacementRange_ = gfx::Range(replacementRange); 3005 setMarkedTextReplacementRange_ = gfx::Range(replacementRange);
2994 } else { 3006 } else {
2995 renderWidgetHostView_->render_widget_host_->ImeSetComposition( 3007 if (renderWidgetHostView_->GetActiveWidget()) {
2996 markedText_, underlines_, gfx::Range(replacementRange), 3008 renderWidgetHostView_->GetActiveWidget()->ImeSetComposition(
2997 newSelRange.location, NSMaxRange(newSelRange)); 3009 markedText_, underlines_, gfx::Range(replacementRange),
3010 newSelRange.location, NSMaxRange(newSelRange));
3011 }
2998 } 3012 }
2999 } 3013 }
3000 3014
3001 - (void)doCommandBySelector:(SEL)selector { 3015 - (void)doCommandBySelector:(SEL)selector {
3002 // An input method calls this function to dispatch an editing command to be 3016 // An input method calls this function to dispatch an editing command to be
3003 // handled by this view. 3017 // handled by this view.
3004 if (selector == @selector(noop:)) 3018 if (selector == @selector(noop:))
3005 return; 3019 return;
3006 3020
3007 std::string command( 3021 std::string command(
(...skipping 14 matching lines...) Expand all
3022 } else { 3036 } else {
3023 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; 3037 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_;
3024 rwh->Send(new InputMsg_ExecuteEditCommand(rwh->GetRoutingID(), 3038 rwh->Send(new InputMsg_ExecuteEditCommand(rwh->GetRoutingID(),
3025 command, "")); 3039 command, ""));
3026 } 3040 }
3027 } 3041 }
3028 3042
3029 - (void)insertText:(id)string replacementRange:(NSRange)replacementRange { 3043 - (void)insertText:(id)string replacementRange:(NSRange)replacementRange {
3030 // An input method has characters to be inserted. 3044 // An input method has characters to be inserted.
3031 // Same as Linux, Mac calls this method not only: 3045 // Same as Linux, Mac calls this method not only:
3032 // * when an input method finishs composing text, but also; 3046 // * when an input method finishes composing text, but also;
3033 // * when we type an ASCII character (without using input methods). 3047 // * when we type an ASCII character (without using input methods).
3034 // When we aren't using input methods, we should send the given character as 3048 // When we aren't using input methods, we should send the given character as
3035 // a Char event so it is dispatched to an onkeypress() event handler of 3049 // a Char event so it is dispatched to an onkeypress() event handler of
3036 // JavaScript. 3050 // JavaScript.
3037 // On the other hand, when we are using input methods, we should send the 3051 // On the other hand, when we are using input methods, we should send the
3038 // given characters as an input method event and prevent the characters from 3052 // given characters as an input method event and prevent the characters from
3039 // being dispatched to onkeypress() event handlers. 3053 // being dispatched to onkeypress() event handlers.
3040 // Text inserting might be initiated by other source instead of keyboard 3054 // Text inserting might be initiated by other source instead of keyboard
3041 // events, such as the Characters dialog. In this case the text should be 3055 // events, such as the Characters dialog. In this case the text should be
3042 // sent as an input method event as well. 3056 // sent as an input method event as well.
3043 // TODO(suzhe): It's hard for us to support replacementRange without accessing 3057 // TODO(suzhe): It's hard for us to support replacementRange without accessing
3044 // the full web content. 3058 // the full web content.
3045 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]]; 3059 BOOL isAttributedString = [string isKindOfClass:[NSAttributedString class]];
3046 NSString* im_text = isAttributedString ? [string string] : string; 3060 NSString* im_text = isAttributedString ? [string string] : string;
3047 if (handlingKeyDown_) { 3061 if (handlingKeyDown_) {
3048 textToBeInserted_.append(base::SysNSStringToUTF16(im_text)); 3062 textToBeInserted_.append(base::SysNSStringToUTF16(im_text));
3049 } else { 3063 } else {
3050 gfx::Range replacement_range(replacementRange); 3064 gfx::Range replacement_range(replacementRange);
3051 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 3065 if (renderWidgetHostView_->GetActiveWidget()) {
3052 base::SysNSStringToUTF16(im_text), replacement_range, false); 3066 renderWidgetHostView_->GetActiveWidget()->ImeConfirmComposition(
3067 base::SysNSStringToUTF16(im_text), replacement_range, false);
3068 }
3053 } 3069 }
3054 3070
3055 // Inserting text will delete all marked text automatically. 3071 // Inserting text will delete all marked text automatically.
3056 hasMarkedText_ = NO; 3072 hasMarkedText_ = NO;
3057 } 3073 }
3058 3074
3059 - (void)insertText:(id)string { 3075 - (void)insertText:(id)string {
3060 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; 3076 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)];
3061 } 3077 }
3062 3078
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3173 3189
3174 hasMarkedText_ = NO; 3190 hasMarkedText_ = NO;
3175 // Should not call [self unmarkText] here, because it'll send unnecessary 3191 // Should not call [self unmarkText] here, because it'll send unnecessary
3176 // cancel composition IPC message to the renderer. 3192 // cancel composition IPC message to the renderer.
3177 } 3193 }
3178 3194
3179 - (void)confirmComposition { 3195 - (void)confirmComposition {
3180 if (!hasMarkedText_) 3196 if (!hasMarkedText_)
3181 return; 3197 return;
3182 3198
3183 if (renderWidgetHostView_->render_widget_host_) 3199 if (renderWidgetHostView_->GetActiveWidget()) {
3184 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 3200 renderWidgetHostView_->GetActiveWidget()->ImeConfirmComposition(
3185 base::string16(), gfx::Range::InvalidRange(), false); 3201 base::string16(), gfx::Range::InvalidRange(), false);
3202 }
3186 3203
3187 [self cancelComposition]; 3204 [self cancelComposition];
3188 } 3205 }
3189 3206
3190 // Overriding a NSResponder method to support application services. 3207 // Overriding a NSResponder method to support application services.
3191 3208
3192 - (id)validRequestorForSendType:(NSString*)sendType 3209 - (id)validRequestorForSendType:(NSString*)sendType
3193 returnType:(NSString*)returnType { 3210 returnType:(NSString*)returnType {
3194 id requestor = nil; 3211 id requestor = nil;
3195 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; 3212 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType];
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3259 3276
3260 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3277 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3261 // regions that are not draggable. (See ControlRegionView in 3278 // regions that are not draggable. (See ControlRegionView in
3262 // native_app_window_cocoa.mm). This requires the render host view to be 3279 // native_app_window_cocoa.mm). This requires the render host view to be
3263 // draggable by default. 3280 // draggable by default.
3264 - (BOOL)mouseDownCanMoveWindow { 3281 - (BOOL)mouseDownCanMoveWindow {
3265 return YES; 3282 return YES;
3266 } 3283 }
3267 3284
3268 @end 3285 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698