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

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

Issue 2164483006: [MacViews] Implemented text context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for tapted Created 4 years 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 <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <objc/runtime.h> 8 #import <objc/runtime.h>
9 #include <OpenGL/gl.h> 9 #include <OpenGL/gl.h>
10 #include <QuartzCore/QuartzCore.h> 10 #include <QuartzCore/QuartzCore.h>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
67 #include "gpu/ipc/common/gpu_messages.h" 67 #include "gpu/ipc/common/gpu_messages.h"
68 #include "skia/ext/platform_canvas.h" 68 #include "skia/ext/platform_canvas.h"
69 #include "skia/ext/skia_utils_mac.h" 69 #include "skia/ext/skia_utils_mac.h"
70 #include "third_party/WebKit/public/platform/WebInputEvent.h" 70 #include "third_party/WebKit/public/platform/WebInputEvent.h"
71 #import "ui/base/clipboard/clipboard_util_mac.h" 71 #import "ui/base/clipboard/clipboard_util_mac.h"
72 #include "ui/base/cocoa/animation_utils.h" 72 #include "ui/base/cocoa/animation_utils.h"
73 #import "ui/base/cocoa/appkit_utils.h" 73 #import "ui/base/cocoa/appkit_utils.h"
74 #include "ui/base/cocoa/cocoa_base_utils.h" 74 #include "ui/base/cocoa/cocoa_base_utils.h"
75 #import "ui/base/cocoa/fullscreen_window_manager.h" 75 #import "ui/base/cocoa/fullscreen_window_manager.h"
76 #include "ui/base/cocoa/text_services_context_menu.h"
76 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" 77 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
77 #include "ui/base/layout.h" 78 #include "ui/base/layout.h"
78 #include "ui/compositor/compositor.h" 79 #include "ui/compositor/compositor.h"
79 #include "ui/compositor/layer.h" 80 #include "ui/compositor/layer.h"
80 #include "ui/display/display.h" 81 #include "ui/display/display.h"
81 #include "ui/display/screen.h" 82 #include "ui/display/screen.h"
82 #include "ui/events/event_utils.h" 83 #include "ui/events/event_utils.h"
83 #include "ui/events/keycodes/keyboard_codes.h" 84 #include "ui/events/keycodes/keyboard_codes.h"
84 #include "ui/gfx/geometry/dip_util.h" 85 #include "ui/gfx/geometry/dip_util.h"
85 #include "ui/gfx/geometry/point.h" 86 #include "ui/gfx/geometry/point.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return render_widget_host_view; 131 return render_widget_host_view;
131 content::WebContents* guest = 132 content::WebContents* guest =
132 guest_manager->GetFullPageGuest(web_contents); 133 guest_manager->GetFullPageGuest(web_contents);
133 if (!guest) 134 if (!guest)
134 return render_widget_host_view; 135 return render_widget_host_view;
135 return guest->GetRenderWidgetHostView(); 136 return guest->GetRenderWidgetHostView();
136 } 137 }
137 138
138 } // namespace 139 } // namespace
139 140
140 // These are not documented, so use only after checking -respondsToSelector:.
141 @interface NSApplication (UndocumentedSpeechMethods)
142 - (void)speakString:(NSString*)string;
143 - (void)stopSpeaking:(id)sender;
144 - (BOOL)isSpeaking;
145 @end
146
147 // Private methods: 141 // Private methods:
148 @interface RenderWidgetHostViewCocoa () 142 @interface RenderWidgetHostViewCocoa ()
149 @property(nonatomic, assign) NSRange selectedRange; 143 @property(nonatomic, assign) NSRange selectedRange;
150 @property(nonatomic, assign) NSRange markedRange; 144 @property(nonatomic, assign) NSRange markedRange;
151 145
152 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; 146 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event;
153 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; 147 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
154 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event 148 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event
155 consumed:(BOOL)consumed; 149 consumed:(BOOL)consumed;
156 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event 150 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 692
699 if (!display_link_->GetVSyncParameters(&vsync_timebase_, &vsync_interval_)) { 693 if (!display_link_->GetVSyncParameters(&vsync_timebase_, &vsync_interval_)) {
700 vsync_timebase_ = base::TimeTicks(); 694 vsync_timebase_ = base::TimeTicks();
701 vsync_interval_ = base::TimeDelta(); 695 vsync_interval_ = base::TimeDelta();
702 return; 696 return;
703 } 697 }
704 698
705 browser_compositor_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_); 699 browser_compositor_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_);
706 } 700 }
707 701
708 void RenderWidgetHostViewMac::SpeakText(const std::string& text) {
709 [NSApp speakString:base::SysUTF8ToNSString(text)];
710 }
711
712 RenderWidgetHostViewBase* 702 RenderWidgetHostViewBase*
713 RenderWidgetHostViewMac::GetFocusedViewForTextSelection() { 703 RenderWidgetHostViewMac::GetFocusedViewForTextSelection() {
714 // We obtain the TextSelection from focused RWH which is obtained from the 704 // We obtain the TextSelection from focused RWH which is obtained from the
715 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree 705 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree
716 // and the focused RWH will be that of the embedder which is incorrect. In 706 // and the focused RWH will be that of the embedder which is incorrect. In
717 // this case we should use TextSelection for |this| since RWHV for guest 707 // this case we should use TextSelection for |this| since RWHV for guest
718 // forwards text selection information to its platform view. 708 // forwards text selection information to its platform view.
719 return is_guest_view_hack_ ? this : GetFocusedWidget() 709 return is_guest_view_hack_ ? this : GetFocusedWidget()
720 ? GetFocusedWidget()->GetView() 710 ? GetFocusedWidget()->GetView()
721 : nullptr; 711 : nullptr;
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // set it again every single time the mouse moves. 1078 // set it again every single time the mouse moves.
1089 base::string16 display_text = tooltip_text_; 1079 base::string16 display_text = tooltip_text_;
1090 if (tooltip_text_.length() > kMaxTooltipLength) 1080 if (tooltip_text_.length() > kMaxTooltipLength)
1091 display_text = tooltip_text_.substr(0, kMaxTooltipLength); 1081 display_text = tooltip_text_.substr(0, kMaxTooltipLength);
1092 1082
1093 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); 1083 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text);
1094 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; 1084 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring];
1095 } 1085 }
1096 } 1086 }
1097 1087
1098 bool RenderWidgetHostViewMac::SupportsSpeech() const {
1099 return [NSApp respondsToSelector:@selector(speakString:)] &&
1100 [NSApp respondsToSelector:@selector(stopSpeaking:)];
1101 }
1102
1103 void RenderWidgetHostViewMac::SpeakSelection() { 1088 void RenderWidgetHostViewMac::SpeakSelection() {
1104 if (![NSApp respondsToSelector:@selector(speakString:)]) 1089 if (![NSApp respondsToSelector:@selector(speakString:)])
1105 return; 1090 return;
1106 1091
1107 if (selected_text_.empty() && render_widget_host_) { 1092 if (selected_text_.empty() && render_widget_host_) {
1108 // If there's no selection, speak all text. Send an asynchronous IPC 1093 // If there's no selection, speak all text. Send an asynchronous IPC
1109 // request for fetching all the text for a webcontent. 1094 // request for fetching all the text for a webcontent.
1110 // ViewMsg_GetRenderedTextCompleted is sent back to IPC Message receiver. 1095 // ViewMsg_GetRenderedTextCompleted is sent back to IPC Message receiver.
1111 render_widget_host_->Send(new ViewMsg_GetRenderedText( 1096 render_widget_host_->Send(new ViewMsg_GetRenderedText(
1112 render_widget_host_->GetRoutingID())); 1097 render_widget_host_->GetRoutingID()));
1113 return; 1098 return;
1114 } 1099 }
1115 1100
1116 SpeakText(selected_text_); 1101 // TODO(spqchan): Change |selected_text_|'s type to string16.
tapted 2016/12/16 07:01:19 I think changing |selected_text_| can be included
spqchan 2016/12/17 00:34:21 Done.
1117 } 1102 ui::TextServicesContextMenu::SpeakText(base::UTF8ToUTF16(selected_text_));
1118
1119 bool RenderWidgetHostViewMac::IsSpeaking() const {
1120 return [NSApp respondsToSelector:@selector(isSpeaking)] &&
1121 [NSApp isSpeaking];
1122 }
1123
1124 void RenderWidgetHostViewMac::StopSpeaking() {
1125 if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
1126 [NSApp stopSpeaking:cocoa_view_];
1127 } 1103 }
1128 1104
1129 // 1105 //
1130 // RenderWidgetHostViewCocoa uses the stored selection text, 1106 // RenderWidgetHostViewCocoa uses the stored selection text,
1131 // which implements NSServicesRequests protocol. 1107 // which implements NSServicesRequests protocol.
1132 // 1108 //
1133 1109
1134 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 1110 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
1135 RenderWidgetHostViewBase::SetShowingContextMenu(showing); 1111 RenderWidgetHostViewBase::SetShowingContextMenu(showing);
1136 1112
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 else 1646 else
1671 DisablePasswordInput(); 1647 DisablePasswordInput();
1672 } else { 1648 } else {
1673 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_PASSWORD) 1649 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_PASSWORD)
1674 DisablePasswordInput(); 1650 DisablePasswordInput();
1675 } 1651 }
1676 } 1652 }
1677 1653
1678 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( 1654 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted(
1679 const std::string& text) { 1655 const std::string& text) {
1680 SpeakText(text); 1656 ui::TextServicesContextMenu::SpeakText(base::UTF8ToUTF16(text));
1681 } 1657 }
1682 1658
1683 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { 1659 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() {
1684 if (!render_widget_host_ || render_widget_host_->is_hidden()) 1660 if (!render_widget_host_ || render_widget_host_->is_hidden())
1685 return; 1661 return;
1686 1662
1687 // Pausing for one view prevents others from receiving frames. 1663 // Pausing for one view prevents others from receiving frames.
1688 // This may lead to large delays, causing overlaps. See crbug.com/352020. 1664 // This may lead to large delays, causing overlaps. See crbug.com/352020.
1689 if (!allow_pause_for_resize_or_repaint_) 1665 if (!allow_pause_for_resize_or_repaint_)
1690 return; 1666 return;
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2737 if (known) 2713 if (known)
2738 return valid; 2714 return valid;
2739 } 2715 }
2740 2716
2741 SEL action = [item action]; 2717 SEL action = [item action];
2742 BOOL is_render_view = 2718 BOOL is_render_view =
2743 RenderViewHost::From(renderWidgetHostView_->render_widget_host_) != 2719 RenderViewHost::From(renderWidgetHostView_->render_widget_host_) !=
2744 nullptr; 2720 nullptr;
2745 2721
2746 if (action == @selector(stopSpeaking:)) 2722 if (action == @selector(stopSpeaking:))
2747 return is_render_view && renderWidgetHostView_->IsSpeaking(); 2723 return is_render_view && ui::TextServicesContextMenu::IsSpeaking();
2748 2724
2749 if (action == @selector(startSpeaking:)) 2725 if (action == @selector(startSpeaking:))
2750 return is_render_view && renderWidgetHostView_->SupportsSpeech(); 2726 return is_render_view;
2751 2727
2752 // For now, these actions are always enabled for render view, 2728 // For now, these actions are always enabled for render view,
2753 // this is sub-optimal. 2729 // this is sub-optimal.
2754 // TODO(suzhe): Plumb the "can*" methods up from WebCore. 2730 // TODO(suzhe): Plumb the "can*" methods up from WebCore.
2755 if (action == @selector(undo:) || 2731 if (action == @selector(undo:) ||
2756 action == @selector(redo:) || 2732 action == @selector(redo:) ||
2757 action == @selector(cut:) || 2733 action == @selector(cut:) ||
2758 action == @selector(copy:) || 2734 action == @selector(copy:) ||
2759 action == @selector(copyToFindPboard:) || 2735 action == @selector(copyToFindPboard:) ||
2760 action == @selector(paste:) || 2736 action == @selector(paste:) ||
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 renderWidgetHostView_->render_widget_host_->delegate(); 3309 renderWidgetHostView_->render_widget_host_->delegate();
3334 if (render_widget_host_delegate) 3310 if (render_widget_host_delegate)
3335 render_widget_host_delegate->SelectAll(); 3311 render_widget_host_delegate->SelectAll();
3336 } 3312 }
3337 3313
3338 - (void)startSpeaking:(id)sender { 3314 - (void)startSpeaking:(id)sender {
3339 GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->SpeakSelection(); 3315 GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->SpeakSelection();
3340 } 3316 }
3341 3317
3342 - (void)stopSpeaking:(id)sender { 3318 - (void)stopSpeaking:(id)sender {
3343 GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->StopSpeaking(); 3319 ui::TextServicesContextMenu::StopSpeaking();
3344 } 3320 }
3345 3321
3346 - (void)cancelComposition { 3322 - (void)cancelComposition {
3347 if (!hasMarkedText_) 3323 if (!hasMarkedText_)
3348 return; 3324 return;
3349 3325
3350 NSTextInputContext* inputContext = [self inputContext]; 3326 NSTextInputContext* inputContext = [self inputContext];
3351 [inputContext discardMarkedText]; 3327 [inputContext discardMarkedText];
3352 3328
3353 hasMarkedText_ = NO; 3329 hasMarkedText_ = NO;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
3438 3414
3439 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3415 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3440 // regions that are not draggable. (See ControlRegionView in 3416 // regions that are not draggable. (See ControlRegionView in
3441 // native_app_window_cocoa.mm). This requires the render host view to be 3417 // native_app_window_cocoa.mm). This requires the render host view to be
3442 // draggable by default. 3418 // draggable by default.
3443 - (BOOL)mouseDownCanMoveWindow { 3419 - (BOOL)mouseDownCanMoveWindow {
3444 return YES; 3420 return YES;
3445 } 3421 }
3446 3422
3447 @end 3423 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698