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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 return; | 692 return; |
693 } | 693 } |
694 | 694 |
695 browser_compositor_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_); | 695 browser_compositor_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_); |
696 } | 696 } |
697 | 697 |
698 void RenderWidgetHostViewMac::SpeakText(const std::string& text) { | 698 void RenderWidgetHostViewMac::SpeakText(const std::string& text) { |
699 [NSApp speakString:base::SysUTF8ToNSString(text)]; | 699 [NSApp speakString:base::SysUTF8ToNSString(text)]; |
700 } | 700 } |
701 | 701 |
702 RenderWidgetHostViewBase* | |
703 RenderWidgetHostViewMac::GetFocusedViewForTextSelection() { | |
704 // We obtain the TextSelection from focused RWH which is obtained from the | |
705 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree | |
706 // and the focused RWH will be that of the embedder which is incorrect. In | |
707 // this case we should use TextSelection for |this| since RWHV for guest | |
708 // forwards text selection information to its platform view. | |
709 return is_guest_view_hack_ ? this : GetFocusedWidget() | |
710 ? GetFocusedWidget()->GetView() | |
711 : nullptr; | |
712 } | |
713 | |
702 void RenderWidgetHostViewMac::UpdateBackingStoreProperties() { | 714 void RenderWidgetHostViewMac::UpdateBackingStoreProperties() { |
703 if (!render_widget_host_) | 715 if (!render_widget_host_) |
704 return; | 716 return; |
705 render_widget_host_->NotifyScreenInfoChanged(); | 717 render_widget_host_->NotifyScreenInfoChanged(); |
706 } | 718 } |
707 | 719 |
708 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 720 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
709 return render_widget_host_; | 721 return render_widget_host_; |
710 } | 722 } |
711 | 723 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
906 GetTextInputManager()->GetCompositionRangeInfo(); | 918 GetTextInputManager()->GetCompositionRangeInfo(); |
907 if (!info) | 919 if (!info) |
908 return; | 920 return; |
909 // The RangeChanged message is only sent with valid values. The current | 921 // The RangeChanged message is only sent with valid values. The current |
910 // caret position (start == end) will be sent if there is no IME range. | 922 // caret position (start == end) will be sent if there is no IME range. |
911 [cocoa_view_ setMarkedRange:info->range.ToNSRange()]; | 923 [cocoa_view_ setMarkedRange:info->range.ToNSRange()]; |
912 composition_range_ = info->range; | 924 composition_range_ = info->range; |
913 composition_bounds_ = info->character_bounds; | 925 composition_bounds_ = info->character_bounds; |
914 } | 926 } |
915 | 927 |
928 void RenderWidgetHostViewMac::OnSelectionBoundsChanged( | |
929 TextInputManager* text_input_manager, | |
930 RenderWidgetHostViewBase* updated_view) { | |
931 DCHECK_EQ(GetTextInputManager(), text_input_manager); | |
932 | |
933 // The rest of the code is to support the Mac Zoom feature tracking the | |
934 // text caret; we can skip it if that feature is not currently enabled. | |
935 if (!UAZoomEnabled()) | |
936 return; | |
937 | |
938 RenderWidgetHostViewBase* focused_view = GetFocusedViewForTextSelection(); | |
939 if (!focused_view) | |
940 return; | |
941 | |
942 const TextInputManager::SelectionRegion* region = | |
943 GetTextInputManager()->GetSelectionRegion(focused_view); | |
944 if (!region) | |
945 return; | |
946 | |
947 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); | |
948 if (!enclosing_window) | |
949 return; | |
950 | |
951 // Create a rectangle for the edge of the selection focus, which will be | |
952 // the same as the caret position if the selection is collapsed. That's | |
953 // what we want to try to keep centered on-screen if possible. | |
954 gfx::Rect gfx_caret_rect(region->focus.edge_top_rounded().x(), | |
955 region->focus.edge_top_rounded().y(), | |
956 1, region->focus.GetHeight()); | |
957 | |
958 // Convert the caret rect to CG-style flipped widget-relative coordinates. | |
959 NSRect caret_rect = NSRectFromCGRect(gfx_caret_rect.ToCGRect()); | |
960 caret_rect.origin.y = NSHeight([cocoa_view_ bounds]) - | |
961 (caret_rect.origin.y + caret_rect.size.height); | |
962 | |
963 // Now convert that to screen coordinates. | |
964 caret_rect = [cocoa_view_ convertRect:caret_rect toView:nil]; | |
965 caret_rect = [enclosing_window convertRectToScreen:caret_rect]; | |
966 | |
967 // Finally, flip it again because UAZoomChangeFocus wants unflipped screen | |
968 // coordinates, and call UAZoomChangeFocus to initiate the scroll. | |
969 caret_rect.origin.y = FlipYFromRectToScreen( | |
970 caret_rect.origin.y, caret_rect.size.height); | |
971 UAZoomChangeFocus(&caret_rect, &caret_rect, kUAZoomFocusTypeInsertionPoint); | |
972 } | |
973 | |
916 void RenderWidgetHostViewMac::OnTextSelectionChanged( | 974 void RenderWidgetHostViewMac::OnTextSelectionChanged( |
917 TextInputManager* text_input_manager, | 975 TextInputManager* text_input_manager, |
918 RenderWidgetHostViewBase* updated_view) { | 976 RenderWidgetHostViewBase* updated_view) { |
919 DCHECK_EQ(GetTextInputManager(), text_input_manager); | 977 DCHECK_EQ(GetTextInputManager(), text_input_manager); |
920 | 978 |
921 // We obtain the TextSelection from focused RWH which is obtained from the | 979 RenderWidgetHostViewBase* focused_view = GetFocusedViewForTextSelection(); |
922 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree | |
923 // and the focused RWH will be that of the embedder which is incorrect. In | |
924 // this case we should use TextSelection for |this| since RWHV for guest | |
925 // forwards text selection information to its platform view. | |
926 RenderWidgetHostViewBase* focused_view = | |
927 is_guest_view_hack_ ? this : GetFocusedWidget() | |
928 ? GetFocusedWidget()->GetView() | |
929 : nullptr; | |
930 | |
931 if (!focused_view) | 980 if (!focused_view) |
932 return; | 981 return; |
933 | 982 |
934 const TextInputManager::TextSelection* selection = | 983 const TextInputManager::TextSelection* selection = |
935 GetTextInputManager()->GetTextSelection(focused_view); | 984 GetTextInputManager()->GetTextSelection(focused_view); |
936 | 985 |
937 base::string16 text; | 986 base::string16 text; |
938 if (selection->GetSelectedText(&text)) | 987 if (selection->GetSelectedText(&text)) |
939 selected_text_ = base::UTF16ToUTF8(text); | 988 selected_text_ = base::UTF16ToUTF8(text); |
940 | 989 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1304 | 1353 |
1305 bool RenderWidgetHostViewMac::HasAcceleratedSurface( | 1354 bool RenderWidgetHostViewMac::HasAcceleratedSurface( |
1306 const gfx::Size& desired_size) { | 1355 const gfx::Size& desired_size) { |
1307 ui::AcceleratedWidgetMac* accelerated_widget_mac = | 1356 ui::AcceleratedWidgetMac* accelerated_widget_mac = |
1308 browser_compositor_->GetAcceleratedWidgetMac(); | 1357 browser_compositor_->GetAcceleratedWidgetMac(); |
1309 if (accelerated_widget_mac) | 1358 if (accelerated_widget_mac) |
1310 return accelerated_widget_mac->HasFrameOfSize(desired_size); | 1359 return accelerated_widget_mac->HasFrameOfSize(desired_size); |
1311 return false; | 1360 return false; |
1312 } | 1361 } |
1313 | 1362 |
1363 void RenderWidgetHostViewMac::FocusedNodeChanged( | |
1364 bool is_editable_node, | |
1365 const gfx::Rect& node_bounds_in_screen) { | |
1366 // If the Mac Zoom featuer is enabled, update it with the bounds of the | |
Alexei Svitkine (slow)
2016/09/22 19:45:20
featuer -> feature
dmazzoni
2016/09/22 20:18:05
Fixed, thanks
| |
1367 // current focused node so that it can ensure that it's scrolled into view. | |
1368 // Don't do anything if it's an editable node, as this will be handled by | |
1369 // OnSelectionBoundsChanged instead. | |
1370 if (UAZoomEnabled() && !is_editable_node) { | |
1371 NSRect bounds = NSRectFromCGRect(node_bounds_in_screen.ToCGRect()); | |
1372 UAZoomChangeFocus(&bounds, NULL, kUAZoomFocusTypeOther); | |
1373 } | |
1374 } | |
1375 | |
1314 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1376 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
1315 uint32_t compositor_frame_sink_id, | 1377 uint32_t compositor_frame_sink_id, |
1316 cc::CompositorFrame frame) { | 1378 cc::CompositorFrame frame) { |
1317 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1379 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
1318 | 1380 |
1319 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1381 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1320 | 1382 |
1321 page_at_minimum_scale_ = | 1383 page_at_minimum_scale_ = |
1322 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; | 1384 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; |
1323 if (frame.delegated_frame_data) { | 1385 if (frame.delegated_frame_data) { |
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3267 | 3329 |
3268 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3330 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3269 // regions that are not draggable. (See ControlRegionView in | 3331 // regions that are not draggable. (See ControlRegionView in |
3270 // native_app_window_cocoa.mm). This requires the render host view to be | 3332 // native_app_window_cocoa.mm). This requires the render host view to be |
3271 // draggable by default. | 3333 // draggable by default. |
3272 - (BOOL)mouseDownCanMoveWindow { | 3334 - (BOOL)mouseDownCanMoveWindow { |
3273 return YES; | 3335 return YES; |
3274 } | 3336 } |
3275 | 3337 |
3276 @end | 3338 @end |
OLD | NEW |