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

Side by Side Diff: ui/views/widget/widget.cc

Issue 2651753003: Wires up ShouldDescendIntoChildForEventHandling() for DesktopNativeWidgetAura (Closed)
Patch Set: improve comments Created 3 years, 11 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 | « ui/views/widget/widget.h ('k') | no next file » | 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 "ui/views/widget/widget.h" 5 #include "ui/views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "ui/aura/window.h"
12 #include "ui/base/cursor/cursor.h" 13 #include "ui/base/cursor/cursor.h"
13 #include "ui/base/default_style.h" 14 #include "ui/base/default_style.h"
14 #include "ui/base/default_theme_provider.h" 15 #include "ui/base/default_theme_provider.h"
15 #include "ui/base/hit_test.h" 16 #include "ui/base/hit_test.h"
16 #include "ui/base/ime/input_method.h" 17 #include "ui/base/ime/input_method.h"
17 #include "ui/base/l10n/l10n_font_util.h" 18 #include "ui/base/l10n/l10n_font_util.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/compositor/compositor.h" 20 #include "ui/compositor/compositor.h"
20 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
21 #include "ui/display/screen.h" 22 #include "ui/display/screen.h"
(...skipping 17 matching lines...) Expand all
39 #include "ui/views/window/custom_frame_view.h" 40 #include "ui/views/window/custom_frame_view.h"
40 #include "ui/views/window/dialog_delegate.h" 41 #include "ui/views/window/dialog_delegate.h"
41 42
42 namespace views { 43 namespace views {
43 44
44 namespace { 45 namespace {
45 46
46 // If |view| has a layer the layer is added to |layers|. Else this recurses 47 // If |view| has a layer the layer is added to |layers|. Else this recurses
47 // through the children. This is used to build a list of the layers created by 48 // through the children. This is used to build a list of the layers created by
48 // views that are direct children of the Widgets layer. 49 // views that are direct children of the Widgets layer.
49 void BuildRootLayers(View* view, std::vector<ui::Layer*>* layers) { 50 void BuildViewsWithLayers(View* view, View::Views* views) {
50 if (view->layer()) { 51 if (view->layer()) {
51 layers->push_back(view->layer()); 52 views->push_back(view);
52 } else { 53 } else {
53 for (int i = 0; i < view->child_count(); ++i) 54 for (int i = 0; i < view->child_count(); ++i)
54 BuildRootLayers(view->child_at(i), layers); 55 BuildViewsWithLayers(view->child_at(i), views);
55 } 56 }
56 } 57 }
57 58
58 // Create a native widget implementation. 59 // Create a native widget implementation.
59 // First, use the supplied one if non-NULL. 60 // First, use the supplied one if non-NULL.
60 // Finally, make a default one. 61 // Finally, make a default one.
61 NativeWidget* CreateNativeWidget(const Widget::InitParams& params, 62 NativeWidget* CreateNativeWidget(const Widget::InitParams& params,
62 internal::NativeWidgetDelegate* delegate) { 63 internal::NativeWidgetDelegate* delegate) {
63 if (params.native_widget) 64 if (params.native_widget)
64 return params.native_widget; 65 return params.native_widget;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 widget_closed_(false), 157 widget_closed_(false),
157 saved_show_state_(ui::SHOW_STATE_DEFAULT), 158 saved_show_state_(ui::SHOW_STATE_DEFAULT),
158 focus_on_creation_(true), 159 focus_on_creation_(true),
159 is_top_level_(false), 160 is_top_level_(false),
160 native_widget_initialized_(false), 161 native_widget_initialized_(false),
161 native_widget_destroyed_(false), 162 native_widget_destroyed_(false),
162 is_mouse_button_pressed_(false), 163 is_mouse_button_pressed_(false),
163 ignore_capture_loss_(false), 164 ignore_capture_loss_(false),
164 last_mouse_event_was_move_(false), 165 last_mouse_event_was_move_(false),
165 auto_release_capture_(true), 166 auto_release_capture_(true),
166 root_layers_dirty_(false), 167 views_with_layers_dirty_(false),
167 movement_disabled_(false), 168 movement_disabled_(false),
168 observer_manager_(this) { 169 observer_manager_(this) {}
169 }
170 170
171 Widget::~Widget() { 171 Widget::~Widget() {
172 DestroyRootView(); 172 DestroyRootView();
173 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) { 173 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) {
174 delete native_widget_; 174 delete native_widget_;
175 } else { 175 } else {
176 DCHECK(native_widget_destroyed_) 176 DCHECK(native_widget_destroyed_)
177 << "Destroying a widget with a live native widget. " 177 << "Destroying a widget with a live native widget. "
178 << "Widget probably should use WIDGET_OWNS_NATIVE_WIDGET ownership."; 178 << "Widget probably should use WIDGET_OWNS_NATIVE_WIDGET ownership.";
179 } 179 }
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 } 907 }
908 908
909 const ui::Layer* Widget::GetLayer() const { 909 const ui::Layer* Widget::GetLayer() const {
910 return native_widget_->GetLayer(); 910 return native_widget_->GetLayer();
911 } 911 }
912 912
913 void Widget::ReorderNativeViews() { 913 void Widget::ReorderNativeViews() {
914 native_widget_->ReorderNativeViews(); 914 native_widget_->ReorderNativeViews();
915 } 915 }
916 916
917 void Widget::UpdateRootLayers() { 917 void Widget::LayerTreeChanged() {
918 // Calculate the layers requires traversing the tree, and since nearly any 918 // Calculate the layers requires traversing the tree, and since nearly any
919 // mutation of the tree can trigger this call we delay until absolutely 919 // mutation of the tree can trigger this call we delay until absolutely
920 // necessary. 920 // necessary.
921 root_layers_dirty_ = true; 921 views_with_layers_dirty_ = true;
922 } 922 }
923 923
924 const NativeWidget* Widget::native_widget() const { 924 const NativeWidget* Widget::native_widget() const {
925 return native_widget_; 925 return native_widget_;
926 } 926 }
927 927
928 NativeWidget* Widget::native_widget() { 928 NativeWidget* Widget::native_widget() {
929 return native_widget_; 929 return native_widget_;
930 } 930 }
931 931
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 // We explicitly do not capture here. Not capturing enables multiple widgets 1269 // We explicitly do not capture here. Not capturing enables multiple widgets
1270 // to get tap events at the same time. Views (such as tab dragging) may 1270 // to get tap events at the same time. Views (such as tab dragging) may
1271 // explicitly capture. 1271 // explicitly capture.
1272 SendEventToProcessor(event); 1272 SendEventToProcessor(event);
1273 } 1273 }
1274 1274
1275 bool Widget::ExecuteCommand(int command_id) { 1275 bool Widget::ExecuteCommand(int command_id) {
1276 return widget_delegate_->ExecuteWindowsCommand(command_id); 1276 return widget_delegate_->ExecuteWindowsCommand(command_id);
1277 } 1277 }
1278 1278
1279 const std::vector<ui::Layer*>& Widget::GetRootLayers() {
1280 if (root_layers_dirty_) {
1281 root_layers_dirty_ = false;
1282 root_layers_.clear();
1283 BuildRootLayers(GetRootView(), &root_layers_);
1284 }
1285 return root_layers_;
1286 }
1287
1288 bool Widget::HasHitTestMask() const { 1279 bool Widget::HasHitTestMask() const {
1289 return widget_delegate_->WidgetHasHitTestMask(); 1280 return widget_delegate_->WidgetHasHitTestMask();
1290 } 1281 }
1291 1282
1292 void Widget::GetHitTestMask(gfx::Path* mask) const { 1283 void Widget::GetHitTestMask(gfx::Path* mask) const {
1293 DCHECK(mask); 1284 DCHECK(mask);
1294 widget_delegate_->GetWidgetHitTestMask(mask); 1285 widget_delegate_->GetWidgetHitTestMask(mask);
1295 } 1286 }
1296 1287
1297 Widget* Widget::AsWidget() { 1288 Widget* Widget::AsWidget() {
(...skipping 18 matching lines...) Expand all
1316 if (v) { 1307 if (v) {
1317 v->RequestFocus(); 1308 v->RequestFocus();
1318 // If the request for focus was unsuccessful, fall back to using the first 1309 // If the request for focus was unsuccessful, fall back to using the first
1319 // focusable View instead. 1310 // focusable View instead.
1320 if (focus_manager && focus_manager->GetFocusedView() == nullptr) 1311 if (focus_manager && focus_manager->GetFocusedView() == nullptr)
1321 focus_manager->AdvanceFocus(false); 1312 focus_manager->AdvanceFocus(false);
1322 } 1313 }
1323 return !!focus_manager->GetFocusedView(); 1314 return !!focus_manager->GetFocusedView();
1324 } 1315 }
1325 1316
1317 bool Widget::ShouldDescendIntoChildForEventHandling(
1318 ui::Layer* root_layer,
1319 gfx::NativeView child,
1320 ui::Layer* child_layer,
1321 const gfx::Point& location) {
1322 if (widget_delegate_ &&
1323 !widget_delegate_->ShouldDescendIntoChildForEventHandling(child,
1324 location)) {
1325 return false;
1326 }
1327
1328 const View::Views& views_with_layers = GetViewsWithLayers();
1329 if (views_with_layers.empty())
1330 return true;
1331
1332 // Don't descend into |child| if there is a view with a Layer that contains
1333 // the point and is stacked above |child_layer|.
1334 auto child_layer_iter = std::find(root_layer->children().begin(),
1335 root_layer->children().end(), child_layer);
1336 if (child_layer_iter == root_layer->children().end())
1337 return true;
1338
1339 for (auto iter = views_with_layers.rbegin(); iter != views_with_layers.rend();
1340 ++iter) {
1341 ui::Layer* layer = (*iter)->layer();
1342 DCHECK(layer);
1343 if (layer->visible() && layer->bounds().Contains(location)) {
1344 auto root_layer_iter = std::find(root_layer->children().begin(),
1345 root_layer->children().end(), layer);
1346 if (child_layer_iter > root_layer_iter) {
1347 // |child| is on top of the remaining layers, no need to continue.
1348 return true;
1349 }
1350
1351 // Event targeting uses the visible bounds of the View, which may differ
1352 // from the bounds of the layer. Verify the view hosting the layer
1353 // actually contains |location|. Use GetVisibleBounds(), which is
1354 // effectively what event targetting uses.
1355 View* view = *iter;
1356 gfx::Rect vis_bounds = view->GetVisibleBounds();
1357 gfx::Point point_in_view = location;
1358 View::ConvertPointToTarget(GetRootView(), view, &point_in_view);
1359 if (vis_bounds.Contains(point_in_view))
1360 return false;
1361 }
1362 }
1363 return true;
1364 }
1365
1326 //////////////////////////////////////////////////////////////////////////////// 1366 ////////////////////////////////////////////////////////////////////////////////
1327 // Widget, ui::EventSource implementation: 1367 // Widget, ui::EventSource implementation:
1328 ui::EventProcessor* Widget::GetEventProcessor() { 1368 ui::EventProcessor* Widget::GetEventProcessor() {
1329 return root_view_.get(); 1369 return root_view_.get();
1330 } 1370 }
1331 1371
1332 //////////////////////////////////////////////////////////////////////////////// 1372 ////////////////////////////////////////////////////////////////////////////////
1333 // Widget, FocusTraversable implementation: 1373 // Widget, FocusTraversable implementation:
1334 1374
1335 FocusSearch* Widget::GetFocusSearch() { 1375 FocusSearch* Widget::GetFocusSearch() {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 bounds->set_width(minimum_size.width()); 1525 bounds->set_width(minimum_size.width());
1486 1526
1487 if (bounds->height() < minimum_size.height()) 1527 if (bounds->height() < minimum_size.height())
1488 bounds->set_height(minimum_size.height()); 1528 bounds->set_height(minimum_size.height());
1489 } 1529 }
1490 return true; 1530 return true;
1491 } 1531 }
1492 return false; 1532 return false;
1493 } 1533 }
1494 1534
1535 const View::Views& Widget::GetViewsWithLayers() {
1536 if (views_with_layers_dirty_) {
1537 views_with_layers_dirty_ = false;
1538 views_with_layers_.clear();
1539 BuildViewsWithLayers(GetRootView(), &views_with_layers_);
1540 }
1541 return views_with_layers_;
1542 }
1543
1495 namespace internal { 1544 namespace internal {
1496 1545
1497 //////////////////////////////////////////////////////////////////////////////// 1546 ////////////////////////////////////////////////////////////////////////////////
1498 // internal::NativeWidgetPrivate, NativeWidget implementation: 1547 // internal::NativeWidgetPrivate, NativeWidget implementation:
1499 1548
1500 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1549 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1501 return this; 1550 return this;
1502 } 1551 }
1503 1552
1504 } // namespace internal 1553 } // namespace internal
1505 } // namespace views 1554 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698