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

Side by Side Diff: chrome/browser/ui/gtk/tabs/window_finder.cc

Issue 231733005: Delete the GTK+ port of Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remerge to ToT Created 6 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/gtk/tabs/window_finder.h"
6
7 #include <gtk/gtk.h>
8
9 #include "base/logging.h"
10 #include "chrome/browser/ui/browser_list.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
13 #include "chrome/browser/ui/gtk/gtk_util.h"
14 #include "chrome/browser/ui/gtk/tabs/tab_gtk.h"
15 #include "chrome/browser/ui/host_desktop.h"
16 #include "ui/base/x/x11_util.h"
17 #include "ui/gfx/native_widget_types.h"
18
19 namespace {
20
21 ////////////////////////////////////////////////////////////////////////////////
22 // BaseWindowFinder
23 //
24 // Base class used to locate a window. A subclass need only override
25 // ShouldStopIterating to determine when iteration should stop.
26 class BaseWindowFinder : public ui::EnumerateWindowsDelegate {
27 public:
28 explicit BaseWindowFinder(const std::set<GtkWidget*>& ignore) {
29 std::set<GtkWidget*>::iterator iter;
30 for (iter = ignore.begin(); iter != ignore.end(); iter++) {
31 XID xid = ui::GetX11WindowFromGtkWidget(*iter);
32 ignore_.insert(xid);
33 }
34 }
35
36 virtual ~BaseWindowFinder() {}
37
38 protected:
39 // Returns true if |window| is in the ignore list.
40 bool ShouldIgnoreWindow(XID window) {
41 return (ignore_.find(window) != ignore_.end());
42 }
43
44 // Returns true if iteration should stop, false otherwise.
45 virtual bool ShouldStopIterating(XID window) OVERRIDE {
46 return false;
47 }
48
49 private:
50 std::set<XID> ignore_;
51
52 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder);
53 };
54
55 ////////////////////////////////////////////////////////////////////////////////
56 // TopMostFinder
57 //
58 // Helper class to determine if a particular point of a window is not obscured
59 // by another window.
60 class TopMostFinder : public BaseWindowFinder {
61 public:
62 // Returns true if |window| is not obscured by another window at the
63 // location |screen_loc|, not including the windows in |ignore|.
64 static bool IsTopMostWindowAtPoint(XID window,
65 const gfx::Point& screen_loc,
66 const std::set<GtkWidget*>& ignore) {
67 TopMostFinder finder(window, screen_loc, ignore);
68 return finder.is_top_most_;
69 }
70
71 protected:
72 virtual bool ShouldStopIterating(XID window) OVERRIDE {
73 if (BaseWindowFinder::ShouldIgnoreWindow(window))
74 return false;
75
76 if (window == target_) {
77 // Window is topmost, stop iterating.
78 is_top_most_ = true;
79 return true;
80 }
81
82 if (!ui::IsWindowVisible(window)) {
83 // The window isn't visible, keep iterating.
84 return false;
85 }
86
87 if (ui::WindowContainsPoint(window, screen_loc_))
88 return true;
89
90 return false;
91 }
92
93 private:
94 TopMostFinder(XID window,
95 const gfx::Point& screen_loc,
96 const std::set<GtkWidget*>& ignore)
97 : BaseWindowFinder(ignore),
98 target_(window),
99 screen_loc_(screen_loc),
100 is_top_most_(false) {
101 ui::EnumerateTopLevelWindows(this);
102 }
103
104 // The window we're looking for.
105 XID target_;
106
107 // Location of window to find.
108 gfx::Point screen_loc_;
109
110 // Is target_ the top most window? This is initially false but set to true
111 // in ShouldStopIterating if target_ is passed in.
112 bool is_top_most_;
113
114 DISALLOW_COPY_AND_ASSIGN(TopMostFinder);
115 };
116
117 ////////////////////////////////////////////////////////////////////////////////
118 // LocalProcessWindowFinder
119 //
120 // Helper class to determine if a particular point of a window from our process
121 // is not obscured by another window.
122 class LocalProcessWindowFinder : public BaseWindowFinder {
123 public:
124 // Returns the XID from our process at screen_loc that is not obscured by
125 // another window. Returns 0 otherwise.
126 static XID GetProcessWindowAtPoint(const gfx::Point& screen_loc,
127 const std::set<GtkWidget*>& ignore) {
128 LocalProcessWindowFinder finder(screen_loc, ignore);
129 if (finder.result_ &&
130 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc,
131 ignore)) {
132 return finder.result_;
133 }
134 return 0;
135 }
136
137 protected:
138 virtual bool ShouldStopIterating(XID window) OVERRIDE {
139 if (BaseWindowFinder::ShouldIgnoreWindow(window))
140 return false;
141
142 // Check if this window is in our process.
143 if (!BrowserWindowGtk::GetBrowserWindowForXID(window))
144 return false;
145
146 if (!ui::IsWindowVisible(window))
147 return false;
148
149 if (ui::WindowContainsPoint(window, screen_loc_)) {
150 result_ = window;
151 return true;
152 }
153
154 return false;
155 }
156
157 private:
158 LocalProcessWindowFinder(const gfx::Point& screen_loc,
159 const std::set<GtkWidget*>& ignore)
160 : BaseWindowFinder(ignore),
161 screen_loc_(screen_loc),
162 result_(0) {
163 ui::EnumerateTopLevelWindows(this);
164 }
165
166 // Position of the mouse.
167 gfx::Point screen_loc_;
168
169 // The resulting window. This is initially null but set to true in
170 // ShouldStopIterating if an appropriate window is found.
171 XID result_;
172
173 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder);
174 };
175
176 } // namespace
177
178 GtkWindow* GetLocalProcessWindowAtPoint(
179 const gfx::Point& screen_point,
180 const std::set<GtkWidget*>& ignore) {
181 XID xid =
182 LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore);
183 return BrowserWindowGtk::GetBrowserWindowForXID(xid);
184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698