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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 #include "gpu/ipc/common/gpu_messages.h" | 66 #include "gpu/ipc/common/gpu_messages.h" |
67 #include "skia/ext/platform_canvas.h" | 67 #include "skia/ext/platform_canvas.h" |
68 #include "skia/ext/skia_utils_mac.h" | 68 #include "skia/ext/skia_utils_mac.h" |
69 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 69 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
70 #include "third_party/WebKit/public/web/WebInputEvent.h" | 70 #include "third_party/WebKit/public/web/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_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/color_profile.h" | 85 #include "ui/gfx/color_profile.h" |
85 #include "ui/gfx/geometry/dip_util.h" | 86 #include "ui/gfx/geometry/dip_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 static_cast<RenderWidgetHostViewMac*>( | 136 return static_cast<RenderWidgetHostViewMac*>( |
136 guest->GetRenderWidgetHostView()); | 137 guest->GetRenderWidgetHostView()); |
137 } | 138 } |
138 | 139 |
139 } // namespace | 140 } // namespace |
140 | 141 |
141 // These are not documented, so use only after checking -respondsToSelector:. | 142 // These are not documented, so use only after checking -respondsToSelector:. |
tapted
2016/07/22 03:06:42
Can these all be deleted? (if callers remain in RW
spqchan
2016/12/12 19:32:27
Done.
| |
142 @interface NSApplication (UndocumentedSpeechMethods) | 143 @interface NSApplication (UndocumentedSpeechMethods) |
143 - (void)speakString:(NSString*)string; | 144 - (void)speakString:(NSString*)string; |
144 - (void)stopSpeaking:(id)sender; | 145 - (void)stopSpeaking:(id)sender; |
145 - (BOOL)isSpeaking; | 146 - (BOOL)isSpeaking; |
146 @end | 147 @end |
147 | 148 |
148 // Private methods: | 149 // Private methods: |
149 @interface RenderWidgetHostViewCocoa () | 150 @interface RenderWidgetHostViewCocoa () |
150 @property(nonatomic, assign) NSRange selectedRange; | 151 @property(nonatomic, assign) NSRange selectedRange; |
151 @property(nonatomic, assign) NSRange markedRange; | 152 @property(nonatomic, assign) NSRange markedRange; |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 vsync_interval_ = base::TimeDelta(); | 867 vsync_interval_ = base::TimeDelta(); |
867 return; | 868 return; |
868 } | 869 } |
869 | 870 |
870 if (browser_compositor_) { | 871 if (browser_compositor_) { |
871 browser_compositor_->compositor()->vsync_manager()->UpdateVSyncParameters( | 872 browser_compositor_->compositor()->vsync_manager()->UpdateVSyncParameters( |
872 vsync_timebase_, vsync_interval_); | 873 vsync_timebase_, vsync_interval_); |
873 } | 874 } |
874 } | 875 } |
875 | 876 |
876 void RenderWidgetHostViewMac::SpeakText(const std::string& text) { | |
877 [NSApp speakString:base::SysUTF8ToNSString(text)]; | |
878 } | |
879 | |
880 void RenderWidgetHostViewMac::UpdateBackingStoreProperties() { | 877 void RenderWidgetHostViewMac::UpdateBackingStoreProperties() { |
881 if (!render_widget_host_) | 878 if (!render_widget_host_) |
882 return; | 879 return; |
883 render_widget_host_->NotifyScreenInfoChanged(); | 880 render_widget_host_->NotifyScreenInfoChanged(); |
884 } | 881 } |
885 | 882 |
886 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 883 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
887 return render_widget_host_; | 884 return render_widget_host_; |
888 } | 885 } |
889 | 886 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1159 // set it again every single time the mouse moves. | 1156 // set it again every single time the mouse moves. |
1160 base::string16 display_text = tooltip_text_; | 1157 base::string16 display_text = tooltip_text_; |
1161 if (tooltip_text_.length() > kMaxTooltipLength) | 1158 if (tooltip_text_.length() > kMaxTooltipLength) |
1162 display_text = tooltip_text_.substr(0, kMaxTooltipLength); | 1159 display_text = tooltip_text_.substr(0, kMaxTooltipLength); |
1163 | 1160 |
1164 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); | 1161 NSString* tooltip_nsstring = base::SysUTF16ToNSString(display_text); |
1165 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; | 1162 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; |
1166 } | 1163 } |
1167 } | 1164 } |
1168 | 1165 |
1169 bool RenderWidgetHostViewMac::SupportsSpeech() const { | |
1170 return [NSApp respondsToSelector:@selector(speakString:)] && | |
1171 [NSApp respondsToSelector:@selector(stopSpeaking:)]; | |
1172 } | |
1173 | |
1174 void RenderWidgetHostViewMac::SpeakSelection() { | 1166 void RenderWidgetHostViewMac::SpeakSelection() { |
1175 if (![NSApp respondsToSelector:@selector(speakString:)]) | 1167 if (![NSApp respondsToSelector:@selector(speakString:)]) |
1176 return; | 1168 return; |
1177 | 1169 |
1178 if (selected_text_.empty() && render_widget_host_) { | 1170 if (selected_text_.empty() && render_widget_host_) { |
1179 // If there's no selection, speak all text. Send an asynchronous IPC | 1171 // If there's no selection, speak all text. Send an asynchronous IPC |
1180 // request for fetching all the text for a webcontent. | 1172 // request for fetching all the text for a webcontent. |
1181 // ViewMsg_GetRenderedTextCompleted is sent back to IPC Message receiver. | 1173 // ViewMsg_GetRenderedTextCompleted is sent back to IPC Message receiver. |
1182 render_widget_host_->Send(new ViewMsg_GetRenderedText( | 1174 render_widget_host_->Send(new ViewMsg_GetRenderedText( |
1183 render_widget_host_->GetRoutingID())); | 1175 render_widget_host_->GetRoutingID())); |
1184 return; | 1176 return; |
1185 } | 1177 } |
1186 | 1178 |
1187 SpeakText(selected_text_); | 1179 TextContextMenu::SpeakText(base::ASCIIToUTF16(selected_text_)); |
tapted
2016/07/22 03:06:42
ASCII -> UTF8
(but also ... the selected_text_ me
spqchan
2016/12/12 19:32:27
Done.
| |
1188 } | |
1189 | |
1190 bool RenderWidgetHostViewMac::IsSpeaking() const { | |
1191 return [NSApp respondsToSelector:@selector(isSpeaking)] && | |
1192 [NSApp isSpeaking]; | |
1193 } | |
1194 | |
1195 void RenderWidgetHostViewMac::StopSpeaking() { | |
1196 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | |
1197 [NSApp stopSpeaking:cocoa_view_]; | |
1198 } | 1180 } |
1199 | 1181 |
1200 // | 1182 // |
1201 // RenderWidgetHostViewCocoa uses the stored selection text, | 1183 // RenderWidgetHostViewCocoa uses the stored selection text, |
1202 // which implements NSServicesRequests protocol. | 1184 // which implements NSServicesRequests protocol. |
1203 // | 1185 // |
1204 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, | 1186 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, |
1205 size_t offset, | 1187 size_t offset, |
1206 const gfx::Range& range) { | 1188 const gfx::Range& range) { |
1207 if (range.is_empty() || text.empty()) { | 1189 if (range.is_empty() || text.empty()) { |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1767 else | 1749 else |
1768 DisablePasswordInput(); | 1750 DisablePasswordInput(); |
1769 } else { | 1751 } else { |
1770 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1752 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
1771 DisablePasswordInput(); | 1753 DisablePasswordInput(); |
1772 } | 1754 } |
1773 } | 1755 } |
1774 | 1756 |
1775 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( | 1757 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( |
1776 const std::string& text) { | 1758 const std::string& text) { |
1777 SpeakText(text); | 1759 TextContextMenu::SpeakText(base::ASCIIToUTF16(text)); |
tapted
2016/07/22 03:06:42
ASCII -> UTF8
spqchan
2016/12/12 19:32:27
Done.
| |
1778 } | 1760 } |
1779 | 1761 |
1780 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { | 1762 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { |
1781 if (!render_widget_host_ || render_widget_host_->is_hidden()) | 1763 if (!render_widget_host_ || render_widget_host_->is_hidden()) |
1782 return; | 1764 return; |
1783 | 1765 |
1784 // Pausing for one view prevents others from receiving frames. | 1766 // Pausing for one view prevents others from receiving frames. |
1785 // This may lead to large delays, causing overlaps. See crbug.com/352020. | 1767 // This may lead to large delays, causing overlaps. See crbug.com/352020. |
1786 if (!allow_pause_for_resize_or_repaint_) | 1768 if (!allow_pause_for_resize_or_repaint_) |
1787 return; | 1769 return; |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2787 if (known) | 2769 if (known) |
2788 return valid; | 2770 return valid; |
2789 } | 2771 } |
2790 | 2772 |
2791 SEL action = [item action]; | 2773 SEL action = [item action]; |
2792 BOOL is_render_view = | 2774 BOOL is_render_view = |
2793 RenderViewHost::From(renderWidgetHostView_->render_widget_host_) != | 2775 RenderViewHost::From(renderWidgetHostView_->render_widget_host_) != |
2794 nullptr; | 2776 nullptr; |
2795 | 2777 |
2796 if (action == @selector(stopSpeaking:)) | 2778 if (action == @selector(stopSpeaking:)) |
2797 return is_render_view && renderWidgetHostView_->IsSpeaking(); | 2779 return is_render_view && TextContextMenu::IsSpeaking(); |
2798 | 2780 |
2799 if (action == @selector(startSpeaking:)) | 2781 if (action == @selector(startSpeaking:)) |
2800 return is_render_view && renderWidgetHostView_->SupportsSpeech(); | 2782 return is_render_view && TextContextMenu::SupportsSpeech(); |
2801 | 2783 |
2802 // For now, these actions are always enabled for render view, | 2784 // For now, these actions are always enabled for render view, |
2803 // this is sub-optimal. | 2785 // this is sub-optimal. |
2804 // TODO(suzhe): Plumb the "can*" methods up from WebCore. | 2786 // TODO(suzhe): Plumb the "can*" methods up from WebCore. |
2805 if (action == @selector(undo:) || | 2787 if (action == @selector(undo:) || |
2806 action == @selector(redo:) || | 2788 action == @selector(redo:) || |
2807 action == @selector(cut:) || | 2789 action == @selector(cut:) || |
2808 action == @selector(copy:) || | 2790 action == @selector(copy:) || |
2809 action == @selector(copyToFindPboard:) || | 2791 action == @selector(copyToFindPboard:) || |
2810 action == @selector(paste:) || | 2792 action == @selector(paste:) || |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3327 // one of the Select methods on RWH. Since selectAll: is called from the | 3309 // one of the Select methods on RWH. Since selectAll: is called from the |
3328 // menu handler, neither is true. | 3310 // menu handler, neither is true. |
3329 // Explicitly call SelectAll() here to make sure the renderer returns | 3311 // Explicitly call SelectAll() here to make sure the renderer returns |
3330 // selection results. | 3312 // selection results. |
3331 content::RenderWidgetHostDelegate* render_widget_host_delegate = | 3313 content::RenderWidgetHostDelegate* render_widget_host_delegate = |
3332 renderWidgetHostView_->render_widget_host_->delegate(); | 3314 renderWidgetHostView_->render_widget_host_->delegate(); |
3333 if (render_widget_host_delegate) | 3315 if (render_widget_host_delegate) |
3334 render_widget_host_delegate->SelectAll(); | 3316 render_widget_host_delegate->SelectAll(); |
3335 } | 3317 } |
3336 | 3318 |
3337 - (void)startSpeaking:(id)sender { | 3319 - (void)startSpeaking:(id)sender { |
tapted
2016/07/22 03:06:42
BridgedContentView will need to implement these if
spqchan
2016/12/12 19:32:27
I'm a bit confused with what you mean about Bridge
tapted
2016/12/12 22:32:44
I think selecting 'Start Speaking' from the mainMe
| |
3338 GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->SpeakSelection(); | 3320 GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->SpeakSelection(); |
3339 } | 3321 } |
3340 | 3322 |
3341 - (void)stopSpeaking:(id)sender { | 3323 - (void)stopSpeaking:(id)sender { |
3342 GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->StopSpeaking(); | 3324 TextContextMenu::StopSpeaking(); |
3343 } | 3325 } |
3344 | 3326 |
3345 - (void)cancelComposition { | 3327 - (void)cancelComposition { |
3346 if (!hasMarkedText_) | 3328 if (!hasMarkedText_) |
3347 return; | 3329 return; |
3348 | 3330 |
3349 // Cancel the ongoing composition. [NSInputManager markedTextAbandoned:] | 3331 // Cancel the ongoing composition. [NSInputManager markedTextAbandoned:] |
3350 // doesn't call any NSTextInput functions, such as setMarkedText or | 3332 // doesn't call any NSTextInput functions, such as setMarkedText or |
3351 // insertText. So, we need to send an IPC message to a renderer so it can | 3333 // insertText. So, we need to send an IPC message to a renderer so it can |
3352 // delete the composition node. | 3334 // delete the composition node. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3446 | 3428 |
3447 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3429 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3448 // regions that are not draggable. (See ControlRegionView in | 3430 // regions that are not draggable. (See ControlRegionView in |
3449 // native_app_window_cocoa.mm). This requires the render host view to be | 3431 // native_app_window_cocoa.mm). This requires the render host view to be |
3450 // draggable by default. | 3432 // draggable by default. |
3451 - (BOOL)mouseDownCanMoveWindow { | 3433 - (BOOL)mouseDownCanMoveWindow { |
3452 return YES; | 3434 return YES; |
3453 } | 3435 } |
3454 | 3436 |
3455 @end | 3437 @end |
OLD | NEW |