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

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

Issue 2240553003: Track text selection on the browser side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the failing tests on 'mac_chromium_rel_ng' 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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 #endif 913 #endif
914 } 914 }
915 } 915 }
916 916
917 void RenderWidgetHostViewMac::OnImeCancelComposition( 917 void RenderWidgetHostViewMac::OnImeCancelComposition(
918 TextInputManager* text_input_manager, 918 TextInputManager* text_input_manager,
919 RenderWidgetHostViewBase* updated_view) { 919 RenderWidgetHostViewBase* updated_view) {
920 [cocoa_view_ cancelComposition]; 920 [cocoa_view_ cancelComposition];
921 } 921 }
922 922
923 void RenderWidgetHostViewMac::OnTextSelectionChanged(
924 TextInputManager* text_input_manager,
925 RenderWidgetHostViewBase* updated_view) {
926 if (!GetTextInputManager())
erikchen 2016/08/12 19:33:43 Can you describe a situation where this conditiona
EhsanK 2016/08/16 13:36:45 Good question. The reason we have this is for futu
927 return;
928
929 RenderWidgetHostViewBase* focused_view = nullptr;
930 if (is_guest_view_hack_) {
erikchen 2016/08/12 19:33:43 This code looks really similar to the logic in Ren
EhsanK 2016/08/16 13:36:45 I added this logic to obtain the focused view into
931 // We obtain the TextSelection from focused RWH which is obtained from the
932 // frame tree. BrowserPlugin-based guests' RWH is not part of the frame tree
933 // and the focused RWH will be that of the embedder which is incorrect. In
934 // this case we should use TextSelection for |this| since RWHV for guest
935 // forwards text selection information to its platform view.
936 focused_view = this;
937 } else if (render_widget_host_ && render_widget_host_->delegate()) {
938 RenderWidgetHostImpl* focused_widget =
939 render_widget_host_->delegate()->GetFocusedRenderWidgetHost(
940 render_widget_host_);
941 if (focused_widget)
942 focused_view = focused_widget->GetView();
943 }
944
945 if (!focused_view)
946 return;
947
948 base::string16 text;
949 if (GetTextInputManager()->GetSelectedText(focused_view, &text))
950 selected_text_ = base::UTF16ToUTF8(text);
951
952 const TextInputManager::TextSelection* selection =
953 GetTextInputManager()->GetTextSelection(focused_view);
erikchen 2016/08/12 19:33:43 The logic for GetTextInputManager()->GetSelectedTe
EhsanK 2016/08/16 13:36:45 Acknowledged.
954 [cocoa_view_ setSelectedRange:selection->range.ToNSRange()];
955 // Updates markedRange when there is no marked text so that retrieving
956 // markedRange immediately after calling setMarkdText: returns the current
957 // caret position.
958 if (![cocoa_view_ hasMarkedText]) {
959 [cocoa_view_ setMarkedRange:selection->range.ToNSRange()];
960 }
961
962 // TODO(ekaramad): The following values are tracked by TextInputManager and
963 // should be cleaned up from this class (https://crbug.com/602427).
964 selection_text_ = selection->text;
EhsanK 2016/08/12 05:07:54 These are also still used by android, so I might a
erikchen 2016/08/12 19:33:43 Why aren't we updating the methods in render_widge
EhsanK 2016/08/16 13:36:45 I am not quite clear on this comment, so I will ex
erikchen 2016/08/16 16:36:22 That's fine.
965 selection_range_ = selection->range;
966 selection_text_offset_ = selection->offset;
967 }
968
923 void RenderWidgetHostViewMac::ImeCompositionRangeChanged( 969 void RenderWidgetHostViewMac::ImeCompositionRangeChanged(
924 const gfx::Range& range, 970 const gfx::Range& range,
925 const std::vector<gfx::Rect>& character_bounds) { 971 const std::vector<gfx::Rect>& character_bounds) {
926 // The RangeChanged message is only sent with valid values. The current 972 // The RangeChanged message is only sent with valid values. The current
927 // caret position (start == end) will be sent if there is no IME range. 973 // caret position (start == end) will be sent if there is no IME range.
928 [cocoa_view_ setMarkedRange:range.ToNSRange()]; 974 [cocoa_view_ setMarkedRange:range.ToNSRange()];
929 composition_range_ = range; 975 composition_range_ = range;
930 composition_bounds_ = character_bounds; 976 composition_bounds_ = character_bounds;
931 } 977 }
932 978
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 1075
1030 void RenderWidgetHostViewMac::StopSpeaking() { 1076 void RenderWidgetHostViewMac::StopSpeaking() {
1031 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) 1077 if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
1032 [NSApp stopSpeaking:cocoa_view_]; 1078 [NSApp stopSpeaking:cocoa_view_];
1033 } 1079 }
1034 1080
1035 // 1081 //
1036 // RenderWidgetHostViewCocoa uses the stored selection text, 1082 // RenderWidgetHostViewCocoa uses the stored selection text,
1037 // which implements NSServicesRequests protocol. 1083 // which implements NSServicesRequests protocol.
1038 // 1084 //
1039 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text,
1040 size_t offset,
1041 const gfx::Range& range) {
1042 if (range.is_empty() || text.empty()) {
1043 selected_text_.clear();
1044 } else {
1045 size_t pos = range.GetMin() - offset;
1046 size_t n = range.length();
1047
1048 DCHECK(pos + n <= text.length()) << "The text can not fully cover range.";
1049 if (pos >= text.length()) {
1050 DCHECK(false) << "The text can not cover range.";
1051 return;
1052 }
1053 selected_text_ = base::UTF16ToUTF8(text.substr(pos, n));
1054 }
1055
1056 [cocoa_view_ setSelectedRange:range.ToNSRange()];
1057 // Updates markedRange when there is no marked text so that retrieving
1058 // markedRange immediately after calling setMarkdText: returns the current
1059 // caret position.
1060 if (![cocoa_view_ hasMarkedText]) {
1061 [cocoa_view_ setMarkedRange:range.ToNSRange()];
1062 }
1063
1064 RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
1065 }
1066 1085
1067 void RenderWidgetHostViewMac::SelectionBoundsChanged( 1086 void RenderWidgetHostViewMac::SelectionBoundsChanged(
1068 const ViewHostMsg_SelectionBounds_Params& params) { 1087 const ViewHostMsg_SelectionBounds_Params& params) {
1069 if (params.anchor_rect == params.focus_rect) 1088 if (params.anchor_rect == params.focus_rect)
1070 caret_rect_ = params.anchor_rect; 1089 caret_rect_ = params.anchor_rect;
1071 first_selection_rect_ = params.anchor_rect; 1090 first_selection_rect_ = params.anchor_rect;
1072 } 1091 }
1073 1092
1074 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 1093 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
1075 RenderWidgetHostViewBase::SetShowingContextMenu(showing); 1094 RenderWidgetHostViewBase::SetShowingContextMenu(showing);
(...skipping 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 3274
3256 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3275 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3257 // regions that are not draggable. (See ControlRegionView in 3276 // regions that are not draggable. (See ControlRegionView in
3258 // native_app_window_cocoa.mm). This requires the render host view to be 3277 // native_app_window_cocoa.mm). This requires the render host view to be
3259 // draggable by default. 3278 // draggable by default.
3260 - (BOOL)mouseDownCanMoveWindow { 3279 - (BOOL)mouseDownCanMoveWindow {
3261 return YES; 3280 return YES;
3262 } 3281 }
3263 3282
3264 @end 3283 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698