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

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

Issue 264713007: Add unittests for X11TopmostWindowFinder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/desktop_aura/x11_topmost_window_finder.h" 5 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
6 6
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 8 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
9 9
10 namespace views { 10 namespace views {
11 11
12 X11TopmostWindowFinder::X11TopmostWindowFinder() : toplevel_(None) { 12 X11TopmostWindowFinder::X11TopmostWindowFinder() : toplevel_(None) {
13 } 13 }
14 14
15 X11TopmostWindowFinder::~X11TopmostWindowFinder() { 15 X11TopmostWindowFinder::~X11TopmostWindowFinder() {
16 } 16 }
17 17
18 aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt( 18 aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt(
19 const gfx::Point& screen_loc, 19 const gfx::Point& screen_loc,
20 const std::set<aura::Window*>& ignore) { 20 const std::set<aura::Window*>& ignore) {
21 screen_loc_ = screen_loc; 21 screen_loc_ = screen_loc;
22 ignore_ = ignore; 22 for (std::set<aura::Window*>::const_iterator it = ignore.begin();
23 it != ignore.end(); ++it) {
24 XID xid = (*it)->GetHost()->GetAcceleratedWidget();
25 cache_.insert(std::make_pair(xid, false));
26 }
23 27
24 std::vector<aura::Window*> local_process_windows = 28 std::vector<aura::Window*> local_process_windows =
25 DesktopWindowTreeHostX11::GetAllOpenWindows(); 29 DesktopWindowTreeHostX11::GetAllOpenWindows();
26 bool found_local_process_window = false; 30 bool found_local_process_window = false;
27 for (size_t i = 0; i < local_process_windows.size(); ++i) { 31 for (size_t i = 0; i < local_process_windows.size(); ++i) {
28 if (ShouldStopIteratingAtLocalProcessWindow(local_process_windows[i])) { 32 XID xid = local_process_windows[i]->GetHost()->GetAcceleratedWidget();
33 if (ShouldStopIterating(xid)) {
34 cache_[xid] = true;
29 found_local_process_window = true; 35 found_local_process_window = true;
30 break; 36 break;
31 } 37 }
38 cache_[xid] = false;
32 } 39 }
33 if (!found_local_process_window) 40 if (!found_local_process_window)
34 return NULL; 41 return NULL;
35 42
36 ui::EnumerateTopLevelWindows(this); 43 ui::EnumerateTopLevelWindows(this);
37 return views::DesktopWindowTreeHostX11::GetContentWindowForXID(toplevel_); 44 return views::DesktopWindowTreeHostX11::GetContentWindowForXID(toplevel_);
38 } 45 }
39 46
40 XID X11TopmostWindowFinder::FindWindowAt(const gfx::Point& screen_loc) { 47 XID X11TopmostWindowFinder::FindWindowAt(const gfx::Point& screen_loc) {
41 screen_loc_ = screen_loc; 48 screen_loc_ = screen_loc;
42 ui::EnumerateTopLevelWindows(this); 49 ui::EnumerateTopLevelWindows(this);
43 return toplevel_; 50 return toplevel_;
44 } 51 }
45 52
46 bool X11TopmostWindowFinder::ShouldStopIterating(XID xid) { 53 bool X11TopmostWindowFinder::ShouldStopIterating(XID xid) {
47 if (!ui::IsWindowVisible(xid)) 54 std::map<XID, bool>::const_iterator it = cache_.find(xid);
48 return false; 55 if (it != cache_.end())
56 return it->second;
49 57
50 aura::Window* window = 58 if (ui::IsWindowVisible(xid) && ui::WindowContainsPoint(xid, screen_loc_)) {
51 views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid);
52 if (window) {
53 if (ShouldStopIteratingAtLocalProcessWindow(window)) {
54 toplevel_ = xid;
55 return true;
56 }
57 return false;
58 }
59
60 if (ui::WindowContainsPoint(xid, screen_loc_)) {
61 toplevel_ = xid; 59 toplevel_ = xid;
62 return true; 60 return true;
63 } 61 }
64 return false; 62 return false;
65 } 63 }
66 64
67 bool X11TopmostWindowFinder::ShouldStopIteratingAtLocalProcessWindow(
68 aura::Window* window) {
69 if (ignore_.find(window) != ignore_.end())
70 return false;
71
72 // Currently |window|->IsVisible() always returns true.
73 // TODO(pkotwicz): Fix this. crbug.com/353038
74 return window->IsVisible() &&
75 window->GetBoundsInScreen().Contains(screen_loc_);
76 }
77
78 } // namespace views 65 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698