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

Side by Side Diff: ui/aura/window_targeter.cc

Issue 2172363002: Created min size for print preview dialog and modified to allow the Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix targeting and missing widget on unit tests. 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/aura/window_targeter.h" 5 #include "ui/aura/window_targeter.h"
6 6
7 #include <memory>
8
7 #include "ui/aura/client/capture_client.h" 9 #include "ui/aura/client/capture_client.h"
8 #include "ui/aura/client/event_client.h" 10 #include "ui/aura/client/event_client.h"
9 #include "ui/aura/client/focus_client.h" 11 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
11 #include "ui/aura/window_delegate.h" 13 #include "ui/aura/window_delegate.h"
12 #include "ui/aura/window_event_dispatcher.h" 14 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/aura/window_tree_host.h" 15 #include "ui/aura/window_tree_host.h"
14 #include "ui/events/event_target.h" 16 #include "ui/events/event_target.h"
15 #include "ui/events/event_target_iterator.h" 17 #include "ui/events/event_target_iterator.h"
16 18
17 namespace aura { 19 namespace aura {
20 const char kHasIndependentBoundsKey[] = "__INDEPENDENT_BOUNDS__";
18 21
19 WindowTargeter::WindowTargeter() {} 22 WindowTargeter::WindowTargeter() {}
20 WindowTargeter::~WindowTargeter() {} 23 WindowTargeter::~WindowTargeter() {}
21 24
22 Window* WindowTargeter::FindTargetForLocatedEvent(Window* window, 25 Window* WindowTargeter::FindTargetForLocatedEvent(Window* window,
23 ui::LocatedEvent* event) { 26 ui::LocatedEvent* event) {
24 if (!window->parent()) { 27 if (!window->parent()) {
25 Window* target = FindTargetInRootWindow(window, *event); 28 Window* target = FindTargetInRootWindow(window, *event);
26 if (target) { 29 if (target) {
27 window->ConvertEventToTarget(target, event); 30 window->ConvertEventToTarget(target, event);
(...skipping 24 matching lines...) Expand all
52 55
53 bool WindowTargeter::EventLocationInsideBounds( 56 bool WindowTargeter::EventLocationInsideBounds(
54 Window* window, 57 Window* window,
55 const ui::LocatedEvent& event) const { 58 const ui::LocatedEvent& event) const {
56 gfx::Point point = event.location(); 59 gfx::Point point = event.location();
57 if (window->parent()) 60 if (window->parent())
58 Window::ConvertPointToTarget(window->parent(), window, &point); 61 Window::ConvertPointToTarget(window->parent(), window, &point);
59 return gfx::Rect(window->bounds().size()).Contains(point); 62 return gfx::Rect(window->bounds().size()).Contains(point);
60 } 63 }
61 64
65 bool WindowTargeter::ChildHasBoundsOutsideParent(Window* parent,
66 Window* child) {
67 if (!parent || !child)
68 return false;
69 return child->GetNativeWindowProperty(aura::kHasIndependentBoundsKey) != NULL;
Lei Zhang 2016/08/18 20:30:57 nit: no NULLs in new code, use nullptr.
rbpotter 2016/08/19 01:59:09 Done.
70 }
71
72 bool WindowTargeter::HasIndependentChildWithEvent(Window* window,
73 gfx::Point point,
74 bool in_parent_coordinates) {
75 Window* parent = window->parent();
76 bool canAccept = true;
Lei Zhang 2016/08/18 20:30:57 nit: can_accept, in_bounds below.
rbpotter 2016/08/19 01:59:09 Done.
77 if (parent) {
78 if (!in_parent_coordinates)
79 Window::ConvertPointToTarget(window, parent, &point);
80 if (parent->delegate_ &&
81 !parent->delegate_->ShouldDescendIntoChildForEventHandling(window,
82 point)) {
83 canAccept = false;
84 }
85 Window::ConvertPointToTarget(parent, window, &point);
86 }
87 bool inBounds = gfx::Rect(window->bounds().size()).Contains(point);
88 canAccept = canAccept && (window->IsVisible() && !window->ignore_events());
89 client::EventClient* client = client::GetEventClient(window->GetRootWindow());
90 if (client && !client->CanProcessEventsWithinSubtree(window))
91 canAccept = false;
92 if (inBounds && canAccept && ChildHasBoundsOutsideParent(parent, window))
93 return true;
94 std::unique_ptr<ui::EventTargetIterator> iter = window->GetChildIterator();
95 if (iter) {
96 for (ui::EventTarget* child = iter->GetNextTarget(); child;
97 child = iter->GetNextTarget()) {
98 if (HasIndependentChildWithEvent(static_cast<Window*>(child), point,
99 true))
100 return true;
101 }
102 }
103 return false;
104 }
105
62 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, 106 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root,
63 ui::Event* event) { 107 ui::Event* event) {
64 Window* window = static_cast<Window*>(root); 108 Window* window = static_cast<Window*>(root);
65 Window* target = event->IsKeyEvent() 109 Window* target = event->IsKeyEvent()
66 ? FindTargetForKeyEvent(window, *event->AsKeyEvent()) 110 ? FindTargetForKeyEvent(window, *event->AsKeyEvent())
67 : FindTargetForNonKeyEvent(window, event); 111 : FindTargetForNonKeyEvent(window, event);
68 if (target && !window->parent() && !window->Contains(target)) { 112 if (target && !window->parent() && !window->Contains(target)) {
69 // |window| is the root window, but |target| is not a descendent of 113 // |window| is the root window, but |target| is not a descendent of
70 // |window|. So do not allow dispatching from here. Instead, dispatch the 114 // |window|. So do not allow dispatching from here. Instead, dispatch the
71 // event through the WindowEventDispatcher that owns |target|. 115 // event through the WindowEventDispatcher that owns |target|.
(...skipping 20 matching lines...) Expand all
92 136
93 ui::EventTarget* WindowTargeter::FindNextBestTarget( 137 ui::EventTarget* WindowTargeter::FindNextBestTarget(
94 ui::EventTarget* previous_target, 138 ui::EventTarget* previous_target,
95 ui::Event* event) { 139 ui::Event* event) {
96 return nullptr; 140 return nullptr;
97 } 141 }
98 142
99 bool WindowTargeter::SubtreeShouldBeExploredForEvent( 143 bool WindowTargeter::SubtreeShouldBeExploredForEvent(
100 Window* window, 144 Window* window,
101 const ui::LocatedEvent& event) { 145 const ui::LocatedEvent& event) {
102 return SubtreeCanAcceptEvent(window, event) && 146 return (SubtreeCanAcceptEvent(window, event) &&
103 EventLocationInsideBounds(window, event); 147 EventLocationInsideBounds(window, event)) ||
148 HasIndependentChildWithEvent(window, event.location(), true);
104 } 149 }
105 150
106 Window* WindowTargeter::FindTargetForKeyEvent(Window* window, 151 Window* WindowTargeter::FindTargetForKeyEvent(Window* window,
107 const ui::KeyEvent& key) { 152 const ui::KeyEvent& key) {
108 Window* root_window = window->GetRootWindow(); 153 Window* root_window = window->GetRootWindow();
109 client::FocusClient* focus_client = client::GetFocusClient(root_window); 154 client::FocusClient* focus_client = client::GetFocusClient(root_window);
110 if (!focus_client) 155 if (!focus_client)
111 return window; 156 return window;
112 Window* focused_window = focus_client->GetFocusedWindow(); 157 Window* focused_window = focus_client->GetFocusedWindow();
113 if (!focused_window) 158 if (!focused_window)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 static_cast<Window*>(targeter->FindTargetForEvent(child, event)); 235 static_cast<Window*>(targeter->FindTargetForEvent(child, event));
191 if (child_target_window) 236 if (child_target_window)
192 return child_target_window; 237 return child_target_window;
193 } 238 }
194 target->ConvertEventToTarget(root_window, event); 239 target->ConvertEventToTarget(root_window, event);
195 } 240 }
196 return root_window->CanAcceptEvent(*event) ? root_window : nullptr; 241 return root_window->CanAcceptEvent(*event) ? root_window : nullptr;
197 } 242 }
198 243
199 } // namespace aura 244 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698