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

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.cc

Issue 1986153005: The on screen keyboard on Windows 8+ should not obscure the input field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address sky unittest review comments Created 4 years, 7 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_view_host_impl.h" 5 #include "content/browser/renderer_host/render_view_host_impl.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 #include "ui/base/touch/touch_device.h" 83 #include "ui/base/touch/touch_device.h"
84 #include "ui/base/touch/touch_enabled.h" 84 #include "ui/base/touch/touch_enabled.h"
85 #include "ui/base/ui_base_switches.h" 85 #include "ui/base/ui_base_switches.h"
86 #include "ui/gfx/animation/animation.h" 86 #include "ui/gfx/animation/animation.h"
87 #include "ui/gfx/image/image_skia.h" 87 #include "ui/gfx/image/image_skia.h"
88 #include "ui/gfx/native_widget_types.h" 88 #include "ui/gfx/native_widget_types.h"
89 #include "ui/native_theme/native_theme_switches.h" 89 #include "ui/native_theme/native_theme_switches.h"
90 #include "url/url_constants.h" 90 #include "url/url_constants.h"
91 91
92 #if defined(OS_WIN) 92 #if defined(OS_WIN)
93 #include "base/win/win_util.h"
94 #include "ui/display/win/dpi.h" 93 #include "ui/display/win/dpi.h"
94 #include "ui/gfx/geometry/dip_util.h"
95 #include "ui/gfx/platform_font_win.h" 95 #include "ui/gfx/platform_font_win.h"
96 #endif 96 #endif
97 97
98 using base::TimeDelta; 98 using base::TimeDelta;
99 using blink::WebConsoleMessage; 99 using blink::WebConsoleMessage;
100 using blink::WebDragOperation; 100 using blink::WebDragOperation;
101 using blink::WebDragOperationNone; 101 using blink::WebDragOperationNone;
102 using blink::WebDragOperationsMask; 102 using blink::WebDragOperationsMask;
103 using blink::WebInputEvent; 103 using blink::WebInputEvent;
104 using blink::WebMediaPlayerAction; 104 using blink::WebMediaPlayerAction;
105 using blink::WebPluginAction; 105 using blink::WebPluginAction;
106 106
107 namespace content { 107 namespace content {
108 namespace { 108 namespace {
109 109
110 #if defined(OS_WIN) 110 #if defined(OS_WIN)
111
112 const int kVirtualKeyboardDisplayWaitTimeoutMs = 100;
113 const int kMaxVirtualKeyboardDisplayRetries = 5;
114
115 void DismissVirtualKeyboardTask() {
116 static int virtual_keyboard_display_retries = 0;
117 // If the virtual keyboard is not yet visible, then we execute the task again
118 // waiting for it to show up.
119 if (!base::win::DismissVirtualKeyboard()) {
120 if (virtual_keyboard_display_retries < kMaxVirtualKeyboardDisplayRetries) {
121 BrowserThread::PostDelayedTask(
122 BrowserThread::UI, FROM_HERE,
123 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask)),
124 TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs));
125 ++virtual_keyboard_display_retries;
126 } else {
127 virtual_keyboard_display_retries = 0;
128 }
129 }
130 }
131
132 void GetWindowsSpecificPrefs(RendererPreferences* prefs) { 111 void GetWindowsSpecificPrefs(RendererPreferences* prefs) {
133 NONCLIENTMETRICS_XP metrics = {0}; 112 NONCLIENTMETRICS_XP metrics = {0};
134 base::win::GetNonClientMetrics(&metrics); 113 base::win::GetNonClientMetrics(&metrics);
135 114
136 prefs->caption_font_family_name = metrics.lfCaptionFont.lfFaceName; 115 prefs->caption_font_family_name = metrics.lfCaptionFont.lfFaceName;
137 prefs->caption_font_height = gfx::PlatformFontWin::GetFontSize( 116 prefs->caption_font_height = gfx::PlatformFontWin::GetFontSize(
138 metrics.lfCaptionFont); 117 metrics.lfCaptionFont);
139 118
140 prefs->small_caption_font_family_name = metrics.lfSmCaptionFont.lfFaceName; 119 prefs->small_caption_font_family_name = metrics.lfSmCaptionFont.lfFaceName;
141 prefs->small_caption_font_height = gfx::PlatformFontWin::GetFontSize( 120 prefs->small_caption_font_height = gfx::PlatformFontWin::GetFontSize(
(...skipping 14 matching lines...) Expand all
156 prefs->vertical_scroll_bar_width_in_dips = 135 prefs->vertical_scroll_bar_width_in_dips =
157 display::win::GetSystemMetricsInDIP(SM_CXVSCROLL); 136 display::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
158 prefs->horizontal_scroll_bar_height_in_dips = 137 prefs->horizontal_scroll_bar_height_in_dips =
159 display::win::GetSystemMetricsInDIP(SM_CYHSCROLL); 138 display::win::GetSystemMetricsInDIP(SM_CYHSCROLL);
160 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = 139 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips =
161 display::win::GetSystemMetricsInDIP(SM_CYVSCROLL); 140 display::win::GetSystemMetricsInDIP(SM_CYVSCROLL);
162 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = 141 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips =
163 display::win::GetSystemMetricsInDIP(SM_CXHSCROLL); 142 display::win::GetSystemMetricsInDIP(SM_CXHSCROLL);
164 } 143 }
165 #endif 144 #endif
166
167 } // namespace 145 } // namespace
168 146
169 // static 147 // static
170 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; 148 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000;
171 149
172 /////////////////////////////////////////////////////////////////////////////// 150 ///////////////////////////////////////////////////////////////////////////////
173 // RenderViewHost, public: 151 // RenderViewHost, public:
174 152
175 // static 153 // static
176 RenderViewHost* RenderViewHost::FromID(int render_process_id, 154 RenderViewHost* RenderViewHost::FromID(int render_process_id,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 delegate_(delegate), 198 delegate_(delegate),
221 instance_(static_cast<SiteInstanceImpl*>(instance)), 199 instance_(static_cast<SiteInstanceImpl*>(instance)),
222 enabled_bindings_(0), 200 enabled_bindings_(0),
223 page_id_(-1), 201 page_id_(-1),
224 is_active_(!swapped_out), 202 is_active_(!swapped_out),
225 is_swapped_out_(swapped_out), 203 is_swapped_out_(swapped_out),
226 main_frame_routing_id_(main_frame_routing_id), 204 main_frame_routing_id_(main_frame_routing_id),
227 is_waiting_for_close_ack_(false), 205 is_waiting_for_close_ack_(false),
228 sudden_termination_allowed_(false), 206 sudden_termination_allowed_(false),
229 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), 207 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING),
230 virtual_keyboard_requested_(false),
231 is_focused_element_editable_(false), 208 is_focused_element_editable_(false),
232 updating_web_preferences_(false), 209 updating_web_preferences_(false),
233 render_view_ready_on_process_launch_(false), 210 render_view_ready_on_process_launch_(false),
234 weak_factory_(this) { 211 weak_factory_(this) {
235 DCHECK(instance_.get()); 212 DCHECK(instance_.get());
236 CHECK(delegate_); // http://crbug.com/82827 213 CHECK(delegate_); // http://crbug.com/82827
237 214
238 GetWidget()->set_owner_delegate(this); 215 GetWidget()->set_owner_delegate(this);
239 216
240 GetProcess()->AddObserver(this); 217 GetProcess()->AddObserver(this);
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 if (view) 1097 if (view)
1121 view->TakeFocus(reverse); 1098 view->TakeFocus(reverse);
1122 } 1099 }
1123 1100
1124 void RenderViewHostImpl::OnFocusedNodeChanged( 1101 void RenderViewHostImpl::OnFocusedNodeChanged(
1125 bool is_editable_node, 1102 bool is_editable_node,
1126 const gfx::Rect& node_bounds_in_viewport) { 1103 const gfx::Rect& node_bounds_in_viewport) {
1127 is_focused_element_editable_ = is_editable_node; 1104 is_focused_element_editable_ = is_editable_node;
1128 if (GetWidget()->GetView()) 1105 if (GetWidget()->GetView())
1129 GetWidget()->GetView()->FocusedNodeChanged(is_editable_node); 1106 GetWidget()->GetView()->FocusedNodeChanged(is_editable_node);
1130 #if defined(OS_WIN)
1131 if (!is_editable_node && virtual_keyboard_requested_) {
1132 virtual_keyboard_requested_ = false;
1133 delegate_->SetIsVirtualKeyboardRequested(false);
1134 BrowserThread::PostDelayedTask(
1135 BrowserThread::UI, FROM_HERE,
1136 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask)),
1137 TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs));
1138 }
1139 #endif
1140 1107
1141 // None of the rest makes sense without a view. 1108 // None of the rest makes sense without a view.
1142 if (!GetWidget()->GetView()) 1109 if (!GetWidget()->GetView())
1143 return; 1110 return;
1144 1111
1145 // Convert node_bounds to screen coordinates. 1112 // Convert node_bounds to screen coordinates.
1146 gfx::Rect view_bounds_in_screen = GetWidget()->GetView()->GetViewBounds(); 1113 gfx::Rect view_bounds_in_screen = GetWidget()->GetView()->GetViewBounds();
1147 gfx::Point origin = node_bounds_in_viewport.origin(); 1114 gfx::Point origin = node_bounds_in_viewport.origin();
1148 origin.Offset(view_bounds_in_screen.x(), view_bounds_in_screen.y()); 1115 origin.Offset(view_bounds_in_screen.x(), view_bounds_in_screen.y());
1149 gfx::Rect node_bounds_in_screen(origin.x(), origin.y(), 1116 gfx::Rect node_bounds_in_screen(origin.x(), origin.y(),
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 bad_message::ReceivedBadMessage(GetProcess(), 1259 bad_message::ReceivedBadMessage(GetProcess(),
1293 bad_message::RVH_FILE_CHOOSER_PATH); 1260 bad_message::RVH_FILE_CHOOSER_PATH);
1294 return; 1261 return;
1295 } 1262 }
1296 1263
1297 delegate_->RunFileChooser(this, params); 1264 delegate_->RunFileChooser(this, params);
1298 } 1265 }
1299 1266
1300 void RenderViewHostImpl::OnFocusedNodeTouched(bool editable) { 1267 void RenderViewHostImpl::OnFocusedNodeTouched(bool editable) {
1301 #if defined(OS_WIN) 1268 #if defined(OS_WIN)
1302 if (editable) { 1269 // We use the cursor position to determine where the touch occurred.
1303 virtual_keyboard_requested_ = base::win::DisplayVirtualKeyboard(); 1270 // TODO(ananta)
1304 delegate_->SetIsVirtualKeyboardRequested(true); 1271 // Pass this information from blink.
1305 } else { 1272 // In site isolation mode, we may not have a RenderViewHostImpl instance
1306 virtual_keyboard_requested_ = false; 1273 // which means that displaying the OSK is not going to work. We should
1307 delegate_->SetIsVirtualKeyboardRequested(false); 1274 // probably move this to RenderWidgetHostImpl and call the view from there.
1308 base::win::DismissVirtualKeyboard(); 1275 // https://bugs.chromium.org/p/chromium/issues/detail?id=613326
1309 } 1276 POINT cursor_pos = {};
1277 ::GetCursorPos(&cursor_pos);
1278 float scale = GetScaleFactorForView(GetWidget()->GetView());
1279 gfx::Point location_dips_screen =
1280 gfx::ConvertPointToDIP(scale, gfx::Point(cursor_pos));
1281 if (GetWidget()->GetView())
1282 GetWidget()->GetView()->FocusedNodeTouched(location_dips_screen, editable);
1310 #endif 1283 #endif
1311 } 1284 }
1312 1285
1313 bool RenderViewHostImpl::CanAccessFilesOfPageState( 1286 bool RenderViewHostImpl::CanAccessFilesOfPageState(
1314 const PageState& state) const { 1287 const PageState& state) const {
1315 ChildProcessSecurityPolicyImpl* policy = 1288 ChildProcessSecurityPolicyImpl* policy =
1316 ChildProcessSecurityPolicyImpl::GetInstance(); 1289 ChildProcessSecurityPolicyImpl::GetInstance();
1317 1290
1318 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); 1291 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles();
1319 for (const auto& file : file_paths) { 1292 for (const auto& file : file_paths) {
(...skipping 28 matching lines...) Expand all
1348 } else { 1321 } else {
1349 render_view_ready_on_process_launch_ = true; 1322 render_view_ready_on_process_launch_ = true;
1350 } 1323 }
1351 } 1324 }
1352 1325
1353 void RenderViewHostImpl::RenderViewReady() { 1326 void RenderViewHostImpl::RenderViewReady() {
1354 delegate_->RenderViewReady(this); 1327 delegate_->RenderViewReady(this);
1355 } 1328 }
1356 1329
1357 } // namespace content 1330 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698