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

Side by Side Diff: chrome/browser/ui/aura/tabs/dock_info_aurax11.cc

Issue 10560014: Aura desktop: Fix tab dragging within a single chrome window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix filename so windows is excluded. Created 8 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 | « chrome/browser/ui/aura/tabs/dock_info_aura.cc ('k') | chrome/browser/ui/gtk/gtk_util.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 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 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/ui/tabs/dock_info.h" 5 #include "chrome/browser/ui/tabs/dock_info.h"
6 6
7 #include <gtk/gtk.h> 7 #include "ui/aura/root_window.h"
8 #include "ui/aura/window.h"
9 #include "ui/base/x/x11_util.h"
10 #include "ui/views/widget/desktop_native_widget_helper_aura.h"
8 11
9 #include "base/logging.h" 12 #if !defined(USE_ASH)
10 #include "chrome/browser/ui/browser_list.h" 13
11 #include "chrome/browser/ui/browser_window.h" 14 namespace {
12 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
13 #include "chrome/browser/ui/gtk/gtk_util.h"
14 #include "ui/base/x/x11_util.h"
15 #include "ui/gfx/native_widget_types.h"
16 15
17 //////////////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////////////
18 // BaseWindowFinder 17 // BaseWindowFinder
19 // 18 //
20 // Base class used to locate a window. A subclass need only override 19 // Base class used to locate a window. A subclass need only override
21 // ShouldStopIterating to determine when iteration should stop. 20 // ShouldStopIterating to determine when iteration should stop.
22 class BaseWindowFinder : public ui::EnumerateWindowsDelegate { 21 class BaseWindowFinder : public ui::EnumerateWindowsDelegate {
23 public: 22 public:
24 explicit BaseWindowFinder(const std::set<GtkWidget*>& ignore) { 23 explicit BaseWindowFinder(const std::set<aura::Window*>& ignore) {
25 std::set<GtkWidget*>::iterator iter; 24 std::set<aura::Window*>::iterator iter;
26 for (iter = ignore.begin(); iter != ignore.end(); iter++) { 25 for (iter = ignore.begin(); iter != ignore.end(); iter++) {
27 XID xid = ui::GetX11WindowFromGtkWidget(*iter); 26 XID xid = (*iter)->GetRootWindow()->GetAcceleratedWidget();
28 ignore_.insert(xid); 27 ignore_.insert(xid);
29 } 28 }
30 } 29 }
31 30
32 virtual ~BaseWindowFinder() {} 31 virtual ~BaseWindowFinder() {}
33 32
34 protected: 33 protected:
35 // Returns true if |window| is in the ignore list. 34 // Returns true if |window| is in the ignore list.
36 bool ShouldIgnoreWindow(XID window) { 35 bool ShouldIgnoreWindow(XID window) {
37 return (ignore_.find(window) != ignore_.end()); 36 return (ignore_.find(window) != ignore_.end());
(...skipping 14 matching lines...) Expand all
52 // TopMostFinder 51 // TopMostFinder
53 // 52 //
54 // Helper class to determine if a particular point of a window is not obscured 53 // Helper class to determine if a particular point of a window is not obscured
55 // by another window. 54 // by another window.
56 class TopMostFinder : public BaseWindowFinder { 55 class TopMostFinder : public BaseWindowFinder {
57 public: 56 public:
58 // Returns true if |window| is not obscured by another window at the 57 // Returns true if |window| is not obscured by another window at the
59 // location |screen_loc|, not including the windows in |ignore|. 58 // location |screen_loc|, not including the windows in |ignore|.
60 static bool IsTopMostWindowAtPoint(XID window, 59 static bool IsTopMostWindowAtPoint(XID window,
61 const gfx::Point& screen_loc, 60 const gfx::Point& screen_loc,
62 const std::set<GtkWidget*>& ignore) { 61 const std::set<aura::Window*>& ignore) {
63 TopMostFinder finder(window, screen_loc, ignore); 62 TopMostFinder finder(window, screen_loc, ignore);
64 return finder.is_top_most_; 63 return finder.is_top_most_;
65 } 64 }
66 65
67 protected: 66 protected:
68 virtual bool ShouldStopIterating(XID window) { 67 virtual bool ShouldStopIterating(XID window) {
69 if (BaseWindowFinder::ShouldIgnoreWindow(window)) 68 if (BaseWindowFinder::ShouldIgnoreWindow(window))
70 return false; 69 return false;
71 70
72 if (window == target_) { 71 if (window == target_) {
(...skipping 15 matching lines...) Expand all
88 // obscuring the target window at this point. 87 // obscuring the target window at this point.
89 return true; 88 return true;
90 } 89 }
91 90
92 return false; 91 return false;
93 } 92 }
94 93
95 private: 94 private:
96 TopMostFinder(XID window, 95 TopMostFinder(XID window,
97 const gfx::Point& screen_loc, 96 const gfx::Point& screen_loc,
98 const std::set<GtkWidget*>& ignore) 97 const std::set<aura::Window*>& ignore)
99 : BaseWindowFinder(ignore), 98 : BaseWindowFinder(ignore),
100 target_(window), 99 target_(window),
101 screen_loc_(screen_loc), 100 screen_loc_(screen_loc),
102 is_top_most_(false) { 101 is_top_most_(false) {
103 gtk_util::EnumerateTopLevelWindows(this); 102 ui::EnumerateTopLevelWindows(this);
104 } 103 }
105 104
106 // The window we're looking for. 105 // The window we're looking for.
107 XID target_; 106 XID target_;
108 107
109 // Location of window to find. 108 // Location of window to find.
110 gfx::Point screen_loc_; 109 gfx::Point screen_loc_;
111 110
112 // Is target_ the top most window? This is initially false but set to true 111 // Is target_ the top most window? This is initially false but set to true
113 // in ShouldStopIterating if target_ is passed in. 112 // in ShouldStopIterating if target_ is passed in.
114 bool is_top_most_; 113 bool is_top_most_;
115 114
116 DISALLOW_COPY_AND_ASSIGN(TopMostFinder); 115 DISALLOW_COPY_AND_ASSIGN(TopMostFinder);
117 }; 116 };
118 117
119 //////////////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////////////////
120 // LocalProcessWindowFinder 119 // LocalProcessWindowFinder
121 // 120 //
122 // Helper class to determine if a particular point of a window from our process 121 // Helper class to determine if a particular point of a window from our process
123 // is not obscured by another window. 122 // is not obscured by another window.
124 class LocalProcessWindowFinder : public BaseWindowFinder { 123 class LocalProcessWindowFinder : public BaseWindowFinder {
125 public: 124 public:
126 // Returns the XID from our process at screen_loc that is not obscured by 125 // Returns the XID from our process at screen_loc that is not obscured by
127 // another window. Returns 0 otherwise. 126 // another window. Returns 0 otherwise.
128 static XID GetProcessWindowAtPoint(const gfx::Point& screen_loc, 127 static XID GetProcessWindowAtPoint(const gfx::Point& screen_loc,
129 const std::set<GtkWidget*>& ignore) { 128 const std::set<aura::Window*>& ignore) {
130 LocalProcessWindowFinder finder(screen_loc, ignore); 129 LocalProcessWindowFinder finder(screen_loc, ignore);
131 if (finder.result_ && 130 if (finder.result_ &&
132 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc, 131 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc,
133 ignore)) { 132 ignore)) {
134 return finder.result_; 133 return finder.result_;
135 } 134 }
136 return 0; 135 return 0;
137 } 136 }
138 137
139 protected: 138 protected:
140 virtual bool ShouldStopIterating(XID window) { 139 virtual bool ShouldStopIterating(XID window) {
141 if (BaseWindowFinder::ShouldIgnoreWindow(window)) 140 if (BaseWindowFinder::ShouldIgnoreWindow(window))
142 return false; 141 return false;
143 142
144 // Check if this window is in our process. 143 // Check if this window is in our process.
145 if (!BrowserWindowGtk::GetBrowserWindowForXID(window)) 144 if (!aura::RootWindow::GetForAcceleratedWidget(window))
146 return false; 145 return false;
147 146
148 if (!ui::IsWindowVisible(window)) 147 if (!ui::IsWindowVisible(window))
149 return false; 148 return false;
150 149
151 gfx::Rect rect; 150 gfx::Rect rect;
152 if (ui::GetWindowRect(window, &rect) && rect.Contains(screen_loc_)) { 151 if (ui::GetWindowRect(window, &rect) && rect.Contains(screen_loc_)) {
153 result_ = window; 152 result_ = window;
154 return true; 153 return true;
155 } 154 }
156 155
157 return false; 156 return false;
158 } 157 }
159 158
160 private: 159 private:
161 LocalProcessWindowFinder(const gfx::Point& screen_loc, 160 LocalProcessWindowFinder(const gfx::Point& screen_loc,
162 const std::set<GtkWidget*>& ignore) 161 const std::set<aura::Window*>& ignore)
163 : BaseWindowFinder(ignore), 162 : BaseWindowFinder(ignore),
164 screen_loc_(screen_loc), 163 screen_loc_(screen_loc),
165 result_(0) { 164 result_(0) {
166 gtk_util::EnumerateTopLevelWindows(this); 165 ui::EnumerateTopLevelWindows(this);
167 } 166 }
168 167
169 // Position of the mouse. 168 // Position of the mouse.
170 gfx::Point screen_loc_; 169 gfx::Point screen_loc_;
171 170
172 // The resulting window. This is initially null but set to true in 171 // The resulting window. This is initially null but set to true in
173 // ShouldStopIterating if an appropriate window is found. 172 // ShouldStopIterating if an appropriate window is found.
174 XID result_; 173 XID result_;
175 174
176 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder); 175 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder);
177 }; 176 };
178 177
178 } // namespace
179
179 // static 180 // static
180 DockInfo DockInfo::GetDockInfoAtPoint(const gfx::Point& screen_point, 181 DockInfo DockInfo::GetDockInfoAtPoint(const gfx::Point& screen_point,
181 const std::set<GtkWidget*>& ignore) { 182 const std::set<gfx::NativeView>& ignore) {
183 // TODO(beng):
182 NOTIMPLEMENTED(); 184 NOTIMPLEMENTED();
183 return DockInfo(); 185 return DockInfo();
184 } 186 }
185 187
186 // static 188 // static
187 GtkWindow* DockInfo::GetLocalProcessWindowAtPoint( 189 gfx::NativeView DockInfo::GetLocalProcessWindowAtPoint(
188 const gfx::Point& screen_point, 190 const gfx::Point& screen_point,
189 const std::set<GtkWidget*>& ignore) { 191 const std::set<gfx::NativeView>& ignore) {
192 // The X11 server is the canonical state of what the window stacking order
193 // is.
190 XID xid = 194 XID xid =
191 LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore); 195 LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore);
192 return BrowserWindowGtk::GetBrowserWindowForXID(xid); 196 aura::RootWindow* root_window =
197 aura::RootWindow::GetForAcceleratedWidget(xid);
198
199 if (!root_window)
200 return NULL;
201
202 // We now have the aura::RootWindow, but most of views isn't interested in
203 // that; instead it wants the aura::Window that is contained by the
204 // RootWindow.
205 return views::DesktopNativeWidgetHelperAura::GetViewsWindowForRootWindow(
206 root_window);
193 } 207 }
194 208
195 bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const { 209 bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const {
196 if (!window()) 210 if (!window())
197 return false; 211 return false;
198 212 *bounds = window_->bounds();
199 int x, y, w, h;
200 gtk_window_get_position(window(), &x, &y);
201 gtk_window_get_size(window(), &w, &h);
202 bounds->SetRect(x, y, w, h);
203 return true; 213 return true;
204 } 214 }
205 215
206 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { 216 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const {
207 gtk_window_move(window(), bounds.x(), bounds.y()); 217 window_->SetBounds(bounds);
208 gtk_window_resize(window(), bounds.width(), bounds.height());
209 } 218 }
219
220 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/aura/tabs/dock_info_aura.cc ('k') | chrome/browser/ui/gtk/gtk_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698