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

Side by Side Diff: content/renderer/render_widget.cc

Issue 2394073002: RenderWidget::windowRect and viewRect should apply device emulation transform. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « content/renderer/render_widget.h ('k') | content/renderer/render_widget_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/render_widget.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 void RenderWidget::Close() { 1329 void RenderWidget::Close() {
1330 screen_metrics_emulator_.reset(); 1330 screen_metrics_emulator_.reset();
1331 WillCloseLayerTreeView(); 1331 WillCloseLayerTreeView();
1332 compositor_.reset(); 1332 compositor_.reset();
1333 if (webwidget_internal_) { 1333 if (webwidget_internal_) {
1334 webwidget_internal_->close(); 1334 webwidget_internal_->close();
1335 webwidget_internal_ = nullptr; 1335 webwidget_internal_ = nullptr;
1336 } 1336 }
1337 } 1337 }
1338 1338
1339 void RenderWidget::ApplyWindowEmulation(WebRect* window_rect) const {
1340 DCHECK(window_rect);
1341 float scale = popup_origin_scale_for_emulation_;
1342 window_rect->x =
1343 popup_view_origin_for_emulation_.x() +
1344 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1345 window_rect->y =
1346 popup_view_origin_for_emulation_.y() +
1347 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1348 }
1349
1350 void RenderWidget::RemoveWindowEmulation(WebRect* window_rect) const {
1351 DCHECK(window_rect);
1352 float scale = popup_origin_scale_for_emulation_;
1353 window_rect->x =
1354 popup_screen_origin_for_emulation_.x() +
1355 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1356 window_rect->y =
1357 popup_screen_origin_for_emulation_.y() +
1358 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1359 }
1360
1339 WebRect RenderWidget::windowRect() { 1361 WebRect RenderWidget::windowRect() {
1362 WebRect rect;
1340 if (pending_window_rect_count_) { 1363 if (pending_window_rect_count_) {
1341 // NOTE(mbelshe): If there is a pending_window_rect_, then getting 1364 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1342 // the RootWindowRect is probably going to return wrong results since the 1365 // the RootWindowRect is probably going to return wrong results since the
1343 // browser may not have processed the Move yet. There isn't really anything 1366 // browser may not have processed the Move yet. There isn't really anything
1344 // good to do in this case, and it shouldn't happen - since this size is 1367 // good to do in this case, and it shouldn't happen - since this size is
1345 // only really needed for windowToScreen, which is only used for Popups. 1368 // only really needed for windowToScreen, which is only used for Popups.
1346 return pending_window_rect_; 1369 rect = pending_window_rect_;
1370 } else {
1371 rect = window_screen_rect_;
1347 } 1372 }
1348 1373
1349 return window_screen_rect_; 1374 if (popup_origin_scale_for_emulation_)
dgozman 2016/10/05 22:40:20 Let's maybe call the method unconditionally and ea
bokan 2016/10/05 22:49:42 Done but added |IfNeeded| to the method name to ma
1375 ApplyWindowEmulation(&rect);
1376
1377 return rect;
1350 } 1378 }
1351 1379
1352 WebRect RenderWidget::viewRect() { 1380 WebRect RenderWidget::viewRect() {
1353 return view_screen_rect_; 1381 WebRect rect = view_screen_rect_;
1382 if (popup_origin_scale_for_emulation_)
1383 ApplyWindowEmulation(&rect);
dgozman 2016/10/05 22:40:20 ScreenRectToEmulated? It's easier to understand co
bokan 2016/10/05 22:49:42 Done.
1384
1385 return rect;
1354 } 1386 }
1355 1387
1356 void RenderWidget::setToolTipText(const blink::WebString& text, 1388 void RenderWidget::setToolTipText(const blink::WebString& text,
1357 WebTextDirection hint) { 1389 WebTextDirection hint) {
1358 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); 1390 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
1359 } 1391 }
1360 1392
1361 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) { 1393 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1362 WebRect window_rect = rect_in_screen; 1394 WebRect window_rect = rect_in_screen;
1363 if (popup_origin_scale_for_emulation_) { 1395 if (popup_origin_scale_for_emulation_)
1364 float scale = popup_origin_scale_for_emulation_; 1396 RemoveWindowEmulation(&window_rect);
dgozman 2016/10/05 22:40:20 EmulatedRectToScreen
bokan 2016/10/05 22:49:42 Done.
1365 window_rect.x = popup_screen_origin_for_emulation_.x() +
1366 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1367 window_rect.y = popup_screen_origin_for_emulation_.y() +
1368 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
1369 }
1370 1397
1371 if (!resizing_mode_selector_->is_synchronous_mode()) { 1398 if (!resizing_mode_selector_->is_synchronous_mode()) {
1372 if (did_show_) { 1399 if (did_show_) {
1373 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); 1400 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1374 SetPendingWindowRect(window_rect); 1401 SetPendingWindowRect(window_rect);
1375 } else { 1402 } else {
1376 initial_rect_ = window_rect; 1403 initial_rect_ = window_rect;
1377 } 1404 }
1378 } else { 1405 } else {
1379 SetWindowRectSynchronously(window_rect); 1406 SetWindowRectSynchronously(window_rect);
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 bool RenderWidget::isPointerLocked() { 2194 bool RenderWidget::isPointerLocked() {
2168 return mouse_lock_dispatcher_->IsMouseLockedTo( 2195 return mouse_lock_dispatcher_->IsMouseLockedTo(
2169 webwidget_mouse_lock_target_.get()); 2196 webwidget_mouse_lock_target_.get());
2170 } 2197 }
2171 2198
2172 blink::WebWidget* RenderWidget::GetWebWidget() const { 2199 blink::WebWidget* RenderWidget::GetWebWidget() const {
2173 return webwidget_internal_; 2200 return webwidget_internal_;
2174 } 2201 }
2175 2202
2176 } // namespace content 2203 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | content/renderer/render_widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698