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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 #include "ui/aura/client/window_parenting_client.h" | 71 #include "ui/aura/client/window_parenting_client.h" |
72 #include "ui/aura/env.h" | 72 #include "ui/aura/env.h" |
73 #include "ui/aura/mus/window_port_mus.h" | 73 #include "ui/aura/mus/window_port_mus.h" |
74 #include "ui/aura/window.h" | 74 #include "ui/aura/window.h" |
75 #include "ui/aura/window_event_dispatcher.h" | 75 #include "ui/aura/window_event_dispatcher.h" |
76 #include "ui/aura/window_observer.h" | 76 #include "ui/aura/window_observer.h" |
77 #include "ui/aura/window_tree_host.h" | 77 #include "ui/aura/window_tree_host.h" |
78 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 78 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
79 #include "ui/base/hit_test.h" | 79 #include "ui/base/hit_test.h" |
80 #include "ui/base/ime/input_method.h" | 80 #include "ui/base/ime/input_method.h" |
81 #include "ui/base/ui_base_switches.h" | |
81 #include "ui/base/ui_base_types.h" | 82 #include "ui/base/ui_base_types.h" |
82 #include "ui/compositor/compositor_vsync_manager.h" | 83 #include "ui/compositor/compositor_vsync_manager.h" |
83 #include "ui/compositor/dip_util.h" | 84 #include "ui/compositor/dip_util.h" |
84 #include "ui/display/display.h" | 85 #include "ui/display/display.h" |
85 #include "ui/display/screen.h" | 86 #include "ui/display/screen.h" |
86 #include "ui/events/blink/blink_event_util.h" | 87 #include "ui/events/blink/blink_event_util.h" |
87 #include "ui/events/blink/web_input_event.h" | 88 #include "ui/events/blink/web_input_event.h" |
88 #include "ui/events/event.h" | 89 #include "ui/events/event.h" |
89 #include "ui/events/event_utils.h" | 90 #include "ui/events/event_utils.h" |
90 #include "ui/events/gesture_detection/gesture_configuration.h" | 91 #include "ui/events/gesture_detection/gesture_configuration.h" |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1260 if (!screen_position_client) | 1261 if (!screen_position_client) |
1261 return rect; | 1262 return rect; |
1262 screen_position_client->ConvertPointToScreen(window_, &origin); | 1263 screen_position_client->ConvertPointToScreen(window_, &origin); |
1263 screen_position_client->ConvertPointToScreen(window_, &end); | 1264 screen_position_client->ConvertPointToScreen(window_, &end); |
1264 return gfx::Rect(origin.x(), | 1265 return gfx::Rect(origin.x(), |
1265 origin.y(), | 1266 origin.y(), |
1266 end.x() - origin.x(), | 1267 end.x() - origin.x(), |
1267 end.y() - origin.y()); | 1268 end.y() - origin.y()); |
1268 } | 1269 } |
1269 | 1270 |
1270 gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen( | 1271 gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen( |
oshima
2017/01/18 02:37:19
this no longer depends on RWHVAura. Can you move t
yhanada
2017/01/30 13:02:47
Done.
| |
1271 const gfx::Rect& rect) const { | 1272 const gfx::Rect& rect, |
1273 aura::Window* window) const { | |
1272 gfx::Point origin = rect.origin(); | 1274 gfx::Point origin = rect.origin(); |
1273 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | 1275 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
1274 | 1276 |
1275 aura::Window* root_window = window_->GetRootWindow(); | 1277 aura::Window* root_window = window->GetRootWindow(); |
1276 if (root_window) { | 1278 if (root_window) { |
1277 aura::client::ScreenPositionClient* screen_position_client = | 1279 aura::client::ScreenPositionClient* screen_position_client = |
1278 aura::client::GetScreenPositionClient(root_window); | 1280 aura::client::GetScreenPositionClient(root_window); |
1279 screen_position_client->ConvertPointFromScreen(window_, &origin); | 1281 if (screen_position_client) { |
1280 screen_position_client->ConvertPointFromScreen(window_, &end); | 1282 screen_position_client->ConvertPointFromScreen(window, &origin); |
1281 return gfx::Rect(origin.x(), | 1283 screen_position_client->ConvertPointFromScreen(window, &end); |
1282 origin.y(), | 1284 return gfx::Rect(origin.x(), origin.y(), end.x() - origin.x(), |
1283 end.x() - origin.x(), | 1285 end.y() - origin.y()); |
1284 end.y() - origin.y()); | 1286 } |
1285 } | 1287 } |
1286 | 1288 |
1287 return rect; | 1289 return rect; |
1288 } | 1290 } |
1289 | 1291 |
1290 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const { | 1292 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const { |
1291 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) | 1293 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) |
1292 return gfx::Rect(); | 1294 return gfx::Rect(); |
1293 | 1295 |
1294 const TextInputManager::SelectionRegion* region = | 1296 const TextInputManager::SelectionRegion* region = |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1415 return true; | 1417 return true; |
1416 } | 1418 } |
1417 | 1419 |
1418 void RenderWidgetHostViewAura::ExtendSelectionAndDelete( | 1420 void RenderWidgetHostViewAura::ExtendSelectionAndDelete( |
1419 size_t before, size_t after) { | 1421 size_t before, size_t after) { |
1420 RenderFrameHostImpl* rfh = GetFocusedFrame(); | 1422 RenderFrameHostImpl* rfh = GetFocusedFrame(); |
1421 if (rfh) | 1423 if (rfh) |
1422 rfh->ExtendSelectionAndDelete(before, after); | 1424 rfh->ExtendSelectionAndDelete(before, after); |
1423 } | 1425 } |
1424 | 1426 |
1425 void RenderWidgetHostViewAura::EnsureCaretNotInRect(const gfx::Rect& rect) { | 1427 void RenderWidgetHostViewAura::EnsureCaretNotInRect( |
1426 gfx::Rect rect_in_local_space = ConvertRectFromScreen(rect); | 1428 const gfx::Rect& rect_in_screen) { |
1427 gfx::Rect hiding_area_in_this_window = | 1429 aura::Window* top_level_window = window_->GetToplevelWindow(); |
1428 gfx::IntersectRects(rect_in_local_space, window_->bounds()); | 1430 gfx::Rect original_window_bounds = top_level_window->GetBoundsInScreen(); |
1431 if (top_level_window->GetProperty( | |
1432 aura::client::kVirtualKeyboardRestoreBoundsKey)) { | |
1433 original_window_bounds = *top_level_window->GetProperty( | |
1434 aura::client::kVirtualKeyboardRestoreBoundsKey); | |
1435 } | |
1429 | 1436 |
1430 if (hiding_area_in_this_window.IsEmpty()) | 1437 const gfx::Rect hiding_area_in_screen = |
oshima
2017/01/18 02:37:19
how about hidden_window_bounds_in_screen?
yhanada
2017/01/30 13:02:47
Done.
| |
1438 gfx::IntersectRects(rect_in_screen, original_window_bounds); | |
1439 | |
1440 if (hiding_area_in_screen.IsEmpty()) { | |
1441 // The window isn't covered by the keyboard, restore the window position if | |
1442 // necessary. | |
1443 OnClientFocusLost(); | |
1444 return; | |
1445 } | |
1446 | |
1447 #if defined(OS_CHROMEOS) | |
1448 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1449 ::switches::kUseNewVirtualKeyboardBehavior)) | |
1431 return; | 1450 return; |
1432 | 1451 |
1433 host_->ScrollFocusedEditableNodeIntoRect( | 1452 // Calculate vertical window shift. |
1434 gfx::SubtractRects(window_->bounds(), hiding_area_in_this_window)); | 1453 const int vertical_displacement = std::max(0, hiding_area_in_screen.height()); |
oshima
2017/01/18 02:37:19
the height should be always positive, right?
yhanada
2017/01/30 13:02:47
Removed this variable.
| |
1454 const int shift = std::min(vertical_displacement, | |
1455 top_level_window->GetBoundsInRootWindow().y()); | |
oshima
2017/01/18 02:37:19
how about:
int top_y = std::max(vk_bounds.y() - t
yhanada
2017/01/30 13:02:47
Done.
| |
1456 | |
1457 // Set restore bounds and move window. | |
1458 if (shift > 0) { | |
1459 top_level_window->SetProperty( | |
1460 aura::client::kVirtualKeyboardRestoreBoundsKey, | |
1461 new gfx::Rect(original_window_bounds)); | |
1462 | |
1463 gfx::Point new_origin(original_window_bounds.x(), | |
1464 original_window_bounds.y() - shift); | |
1465 gfx::Rect new_window_bounds_in_root_window_space = ConvertRectFromScreen( | |
1466 gfx::Rect(new_origin, original_window_bounds.size()), | |
1467 top_level_window->GetRootWindow()); | |
1468 top_level_window->SetBounds(new_window_bounds_in_root_window_space); | |
1469 } else { | |
1470 // No need to move the window or need to restore the window position. | |
1471 OnClientFocusLost(); | |
1472 } | |
1473 #endif // defined(OS_CHROMEOS) | |
1474 | |
1475 // Perform overscroll if the caret is still hidden by the keyboard. | |
1476 gfx::Rect visible_area_in_local_space(ConvertRectFromScreen( | |
1477 gfx::SubtractRects(window_->GetBoundsInScreen(), hiding_area_in_screen), | |
1478 window_)); | |
1479 host_->ScrollFocusedEditableNodeIntoRect(visible_area_in_local_space); | |
1480 } | |
1481 | |
1482 void RenderWidgetHostViewAura::OnClientFocusLost() { | |
1483 #if defined(OS_CHROMEOS) | |
1484 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1485 ::switches::kUseNewVirtualKeyboardBehavior)) | |
1486 return; | |
1487 | |
1488 LOG(ERROR) << "OnClientFocusLost is called"; | |
oshima
2017/01/18 02:37:19
nit: remove debug log
yhanada
2017/01/30 13:02:47
Done.
| |
1489 | |
1490 // Get restore bounds of window. | |
1491 aura::Window* top_level_window = window_->GetToplevelWindow(); | |
1492 gfx::Rect* vk_restore_bounds = top_level_window->GetProperty( | |
1493 aura::client::kVirtualKeyboardRestoreBoundsKey); | |
1494 | |
1495 if (vk_restore_bounds) { | |
1496 // Restore window. | |
1497 // TODO(yhanada): Clarify behavior when a user has moved a window while the | |
1498 // keyboard is shown. See crbug.com/624521. | |
1499 if (top_level_window->GetBoundsInScreen() != *vk_restore_bounds) { | |
1500 top_level_window->SetBounds(ConvertRectFromScreen( | |
1501 *vk_restore_bounds, top_level_window->GetRootWindow())); | |
1502 } | |
1503 top_level_window->ClearProperty( | |
1504 aura::client::kVirtualKeyboardRestoreBoundsKey); | |
1505 } | |
1506 #endif // defined(OS_CHROMEOS) | |
1435 } | 1507 } |
1436 | 1508 |
1437 bool RenderWidgetHostViewAura::IsTextEditCommandEnabled( | 1509 bool RenderWidgetHostViewAura::IsTextEditCommandEnabled( |
1438 ui::TextEditCommand command) const { | 1510 ui::TextEditCommand command) const { |
1439 return false; | 1511 return false; |
1440 } | 1512 } |
1441 | 1513 |
1442 void RenderWidgetHostViewAura::SetTextEditCommandForNextKeyEvent( | 1514 void RenderWidgetHostViewAura::SetTextEditCommandForNextKeyEvent( |
1443 ui::TextEditCommand command) {} | 1515 ui::TextEditCommand command) {} |
1444 | 1516 |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2379 | 2451 |
2380 void RenderWidgetHostViewAura::SetPopupChild( | 2452 void RenderWidgetHostViewAura::SetPopupChild( |
2381 RenderWidgetHostViewAura* popup_child_host_view) { | 2453 RenderWidgetHostViewAura* popup_child_host_view) { |
2382 popup_child_host_view_ = popup_child_host_view; | 2454 popup_child_host_view_ = popup_child_host_view; |
2383 event_handler_->SetPopupChild( | 2455 event_handler_->SetPopupChild( |
2384 popup_child_host_view, | 2456 popup_child_host_view, |
2385 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr); | 2457 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr); |
2386 } | 2458 } |
2387 | 2459 |
2388 } // namespace content | 2460 } // namespace content |
OLD | NEW |