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

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 Mac compile error. 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
« ui/aura/window_targeter.h ('K') | « ui/aura/window_targeter.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) 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
70 child->GetNativeWindowProperty(aura::kHasIndependentBoundsKey) != nullptr;
Lei Zhang 2016/08/19 03:28:47 Or !!foo is you want it to fit on one line again.
rbpotter 2016/08/19 16:59:42 Done.
71 }
72
73 bool WindowTargeter::HasIndependentChildWithEvent(Window* window,
74 const gfx::Point& event_point,
75 bool in_parent_coordinates) {
76 gfx::Point point(event_point);
77 Window* parent = window->parent();
78 bool can_accept = true;
79 if (parent) {
80 if (!in_parent_coordinates)
81 Window::ConvertPointToTarget(window, parent, &point);
82 if (parent->delegate_ &&
83 !parent->delegate_->ShouldDescendIntoChildForEventHandling(window,
84 point)) {
85 can_accept = false;
86 }
87 Window::ConvertPointToTarget(parent, window, &point);
88 }
89 bool in_bounds = gfx::Rect(window->bounds().size()).Contains(point);
90 can_accept = can_accept && (window->IsVisible() && !window->ignore_events());
91 client::EventClient* client = client::GetEventClient(window->GetRootWindow());
92 if (client && !client->CanProcessEventsWithinSubtree(window))
93 can_accept = false;
94 if (in_bounds && can_accept && ChildHasBoundsOutsideParent(parent, window))
95 return true;
96 std::unique_ptr<ui::EventTargetIterator> iter = window->GetChildIterator();
97 if (iter) {
98 for (ui::EventTarget* child = iter->GetNextTarget(); child;
99 child = iter->GetNextTarget()) {
100 if (HasIndependentChildWithEvent(static_cast<Window*>(child), point,
101 true))
102 return true;
103 }
Lei Zhang 2016/08/19 03:28:47 bad indent
rbpotter 2016/08/19 16:59:42 Done.
104 }
105 return false;
106 }
107
62 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, 108 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root,
63 ui::Event* event) { 109 ui::Event* event) {
64 Window* window = static_cast<Window*>(root); 110 Window* window = static_cast<Window*>(root);
65 Window* target = event->IsKeyEvent() 111 Window* target = event->IsKeyEvent()
66 ? FindTargetForKeyEvent(window, *event->AsKeyEvent()) 112 ? FindTargetForKeyEvent(window, *event->AsKeyEvent())
67 : FindTargetForNonKeyEvent(window, event); 113 : FindTargetForNonKeyEvent(window, event);
68 if (target && !window->parent() && !window->Contains(target)) { 114 if (target && !window->parent() && !window->Contains(target)) {
69 // |window| is the root window, but |target| is not a descendent of 115 // |window| is the root window, but |target| is not a descendent of
70 // |window|. So do not allow dispatching from here. Instead, dispatch the 116 // |window|. So do not allow dispatching from here. Instead, dispatch the
71 // event through the WindowEventDispatcher that owns |target|. 117 // event through the WindowEventDispatcher that owns |target|.
(...skipping 20 matching lines...) Expand all
92 138
93 ui::EventTarget* WindowTargeter::FindNextBestTarget( 139 ui::EventTarget* WindowTargeter::FindNextBestTarget(
94 ui::EventTarget* previous_target, 140 ui::EventTarget* previous_target,
95 ui::Event* event) { 141 ui::Event* event) {
96 return nullptr; 142 return nullptr;
97 } 143 }
98 144
99 bool WindowTargeter::SubtreeShouldBeExploredForEvent( 145 bool WindowTargeter::SubtreeShouldBeExploredForEvent(
100 Window* window, 146 Window* window,
101 const ui::LocatedEvent& event) { 147 const ui::LocatedEvent& event) {
102 return SubtreeCanAcceptEvent(window, event) && 148 return (SubtreeCanAcceptEvent(window, event) &&
103 EventLocationInsideBounds(window, event); 149 EventLocationInsideBounds(window, event)) ||
150 HasIndependentChildWithEvent(window, event.location(), true);
104 } 151 }
105 152
106 Window* WindowTargeter::FindTargetForKeyEvent(Window* window, 153 Window* WindowTargeter::FindTargetForKeyEvent(Window* window,
107 const ui::KeyEvent& key) { 154 const ui::KeyEvent& key) {
108 Window* root_window = window->GetRootWindow(); 155 Window* root_window = window->GetRootWindow();
109 client::FocusClient* focus_client = client::GetFocusClient(root_window); 156 client::FocusClient* focus_client = client::GetFocusClient(root_window);
110 if (!focus_client) 157 if (!focus_client)
111 return window; 158 return window;
112 Window* focused_window = focus_client->GetFocusedWindow(); 159 Window* focused_window = focus_client->GetFocusedWindow();
113 if (!focused_window) 160 if (!focused_window)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 static_cast<Window*>(targeter->FindTargetForEvent(child, event)); 237 static_cast<Window*>(targeter->FindTargetForEvent(child, event));
191 if (child_target_window) 238 if (child_target_window)
192 return child_target_window; 239 return child_target_window;
193 } 240 }
194 target->ConvertEventToTarget(root_window, event); 241 target->ConvertEventToTarget(root_window, event);
195 } 242 }
196 return root_window->CanAcceptEvent(*event) ? root_window : nullptr; 243 return root_window->CanAcceptEvent(*event) ? root_window : nullptr;
197 } 244 }
198 245
199 } // namespace aura 246 } // namespace aura
OLDNEW
« ui/aura/window_targeter.h ('K') | « ui/aura/window_targeter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698