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

Side by Side Diff: chrome/browser/dock_info_gtk.cc

Issue 119345: Use the convenience function gdk_screen_get_window_stack to enumerate top-lev... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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
« no previous file with comments | « no previous file | chrome/common/gtk_util.h » ('j') | chrome/common/x11_util.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/dock_info.h" 5 #include "chrome/browser/dock_info.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/gfx/native_widget_types.h" 9 #include "base/gfx/native_widget_types.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "chrome/browser/browser_list.h" 12 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser_window.h" 13 #include "chrome/browser/browser_window.h"
14 #include "chrome/browser/gtk/browser_window_gtk.h" 14 #include "chrome/browser/gtk/browser_window_gtk.h"
15 #include "chrome/common/x11_util.h" 15 #include "chrome/common/gtk_util.h"
16 16
17 //////////////////////////////////////////////////////////////////////////////// 17 ////////////////////////////////////////////////////////////////////////////////
18 // BaseWindowFinder 18 // BaseWindowFinder
19 // 19 //
20 // Base class used to locate a window. A subclass need only override 20 // Base class used to locate a window. A subclass need only override
21 // ShouldStopIterating to determine when iteration should stop. 21 // ShouldStopIterating to determine when iteration should stop.
22 class BaseWindowFinder : public x11_util::EnumerateWindowsDelegate { 22 class BaseWindowFinder : public gtk_util::EnumerateWindowsDelegate {
23 public: 23 public:
24 explicit BaseWindowFinder(const std::set<GtkWidget*>& ignore) { 24 explicit BaseWindowFinder(const std::set<GtkWidget*>& ignore) {
25 std::set<GtkWidget*>::iterator iter; 25 std::set<GtkWidget*>::iterator iter;
26 for (iter = ignore.begin(); iter != ignore.end(); iter++) { 26 for (iter = ignore.begin(); iter != ignore.end(); iter++) {
27 XID xid = x11_util::GetX11WindowFromGtkWidget(*iter); 27 XID xid = x11_util::GetX11WindowFromGtkWidget(*iter);
28 ignore_.insert(xid); 28 ignore_.insert(xid);
29 } 29 }
30 } 30 }
31 31
32 virtual ~BaseWindowFinder() {} 32 virtual ~BaseWindowFinder() {}
33 33
34 protected: 34 protected:
35 // Returns true if iteration should stop, false otherwise. 35 // Returns true if |window| is in the ignore list.
36 virtual bool ShouldStopIterating(XID window) { 36 bool ShouldIgnoreWindow(XID window) {
37 return (ignore_.find(window) != ignore_.end()); 37 return (ignore_.find(window) != ignore_.end());
38 } 38 }
39 39
40 // Returns true if iteration should stop, false otherwise.
41 virtual bool ShouldStopIterating(XID window) {
42 return false;
43 }
44
40 private: 45 private:
41 std::set<XID> ignore_; 46 std::set<XID> ignore_;
42 47
43 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder); 48 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder);
44 }; 49 };
45 50
46 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
47 // TopMostFinder 52 // TopMostFinder
48 // 53 //
49 // Helper class to determine if a particular point of a window is not obscured 54 // Helper class to determine if a particular point of a window is not obscured
50 // by another window. 55 // by another window.
51 class TopMostFinder : public BaseWindowFinder { 56 class TopMostFinder : public BaseWindowFinder {
52 public: 57 public:
53 // Returns true if |window| is not obscured by another window at the 58 // Returns true if |window| is not obscured by another window at the
54 // location |screen_loc|, not including the windows in |ignore|. 59 // location |screen_loc|, not including the windows in |ignore|.
55 static bool IsTopMostWindowAtPoint(XID window, 60 static bool IsTopMostWindowAtPoint(XID window,
56 const gfx::Point& screen_loc, 61 const gfx::Point& screen_loc,
57 const std::set<GtkWidget*>& ignore) { 62 const std::set<GtkWidget*>& ignore) {
58 TopMostFinder finder(window, screen_loc, ignore); 63 TopMostFinder finder(window, screen_loc, ignore);
59 return finder.is_top_most_; 64 return finder.is_top_most_;
60 } 65 }
61 66
62 protected: 67 protected:
63 virtual bool ShouldStopIterating(XID window) { 68 virtual bool ShouldStopIterating(XID window) {
64 if (BaseWindowFinder::ShouldStopIterating(window)) 69 if (BaseWindowFinder::ShouldIgnoreWindow(window))
65 return true; 70 return false;
66 71
67 if (window == target_) { 72 if (window == target_) {
68 // Window is topmost, stop iterating. 73 // Window is topmost, stop iterating.
69 is_top_most_ = true; 74 is_top_most_ = true;
70 return true; 75 return true;
71 } 76 }
72 77
73 if (x11_util::IsWindowVisible(window)) { 78 if (x11_util::IsWindowVisible(window)) {
74 // The window isn't visible, keep iterating. 79 // The window isn't visible, keep iterating.
75 return false; 80 return false;
(...skipping 12 matching lines...) Expand all
88 } 93 }
89 94
90 private: 95 private:
91 TopMostFinder(XID window, 96 TopMostFinder(XID window,
92 const gfx::Point& screen_loc, 97 const gfx::Point& screen_loc,
93 const std::set<GtkWidget*>& ignore) 98 const std::set<GtkWidget*>& ignore)
94 : BaseWindowFinder(ignore), 99 : BaseWindowFinder(ignore),
95 target_(window), 100 target_(window),
96 screen_loc_(screen_loc), 101 screen_loc_(screen_loc),
97 is_top_most_(false) { 102 is_top_most_(false) {
98 XID root = x11_util::GetX11RootWindow(); 103 gtk_util::EnumerateChildWindows(this);
99 x11_util::EnumerateChildWindows(root, this);
100 } 104 }
101 105
102 // The window we're looking for. 106 // The window we're looking for.
103 XID target_; 107 XID target_;
104 108
105 // Location of window to find. 109 // Location of window to find.
106 gfx::Point screen_loc_; 110 gfx::Point screen_loc_;
107 111
108 // Is target_ the top most window? This is initially false but set to true 112 // Is target_ the top most window? This is initially false but set to true
109 // in ShouldStopIterating if target_ is passed in. 113 // in ShouldStopIterating if target_ is passed in.
(...skipping 17 matching lines...) Expand all
127 if (finder.result_ && 131 if (finder.result_ &&
128 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc, 132 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc,
129 ignore)) { 133 ignore)) {
130 return finder.result_; 134 return finder.result_;
131 } 135 }
132 return 0; 136 return 0;
133 } 137 }
134 138
135 protected: 139 protected:
136 virtual bool ShouldStopIterating(XID window) { 140 virtual bool ShouldStopIterating(XID window) {
137 if (BaseWindowFinder::ShouldStopIterating(window)) 141 if (BaseWindowFinder::ShouldIgnoreWindow(window))
138 return true; 142 return false;
139 143
140 // Check if this window is in our process. 144 // Check if this window is in our process.
141 if (!BrowserWindowGtk::GetBrowserWindowForXID(window)) 145 if (!BrowserWindowGtk::GetBrowserWindowForXID(window))
142 return false; 146 return false;
143 147
144 if (!x11_util::IsWindowVisible(window)) 148 if (!x11_util::IsWindowVisible(window))
145 return false; 149 return false;
146 150
147 gfx::Rect rect; 151 gfx::Rect rect;
148 if (x11_util::GetWindowRect(window, &rect) && rect.Contains(screen_loc_)) { 152 if (x11_util::GetWindowRect(window, &rect) && rect.Contains(screen_loc_)) {
149 result_ = window; 153 result_ = window;
150 return true; 154 return true;
151 } 155 }
152 156
153 return false; 157 return false;
154 } 158 }
155 159
156 private: 160 private:
157 LocalProcessWindowFinder(const gfx::Point& screen_loc, 161 LocalProcessWindowFinder(const gfx::Point& screen_loc,
158 const std::set<GtkWidget*>& ignore) 162 const std::set<GtkWidget*>& ignore)
159 : BaseWindowFinder(ignore), 163 : BaseWindowFinder(ignore),
160 screen_loc_(screen_loc), 164 screen_loc_(screen_loc),
161 result_(0) { 165 result_(0) {
162 XID root = x11_util::GetX11RootWindow(); 166 gtk_util::EnumerateChildWindows(this);
163 x11_util::EnumerateChildWindows(root, this);
164 } 167 }
165 168
166 // Position of the mouse. 169 // Position of the mouse.
167 gfx::Point screen_loc_; 170 gfx::Point screen_loc_;
168 171
169 // The resulting window. This is initially null but set to true in 172 // The resulting window. This is initially null but set to true in
170 // ShouldStopIterating if an appropriate window is found. 173 // ShouldStopIterating if an appropriate window is found.
171 XID result_; 174 XID result_;
172 175
173 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder); 176 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 gtk_window_get_position(window(), &x, &y); 210 gtk_window_get_position(window(), &x, &y);
208 gtk_window_get_size(window(), &w, &h); 211 gtk_window_get_size(window(), &w, &h);
209 bounds->SetRect(x, y, w, h); 212 bounds->SetRect(x, y, w, h);
210 return true; 213 return true;
211 } 214 }
212 215
213 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { 216 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const {
214 gtk_window_move(window(), bounds.x(), bounds.y()); 217 gtk_window_move(window(), bounds.x(), bounds.y());
215 gtk_window_resize(window(), bounds.width(), bounds.height()); 218 gtk_window_resize(window(), bounds.width(), bounds.height());
216 } 219 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/gtk_util.h » ('j') | chrome/common/x11_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698