Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / aura / tabs / dock_info_auralinux.cc
blob298e72be67398feaf879d59c34cb5ccde3177d3f
1 // Copyright 2013 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.
5 #include "chrome/browser/ui/tabs/dock_info.h"
7 #include "base/debug/trace_event.h"
8 #include "chrome/browser/ui/host_desktop.h"
9 #include "ui/aura/root_window.h"
10 #include "ui/aura/window.h"
11 #if defined(USE_X11)
12 #include "ui/base/x/x11_util.h"
13 #endif
15 #if !defined(OS_CHROMEOS) && defined(USE_X11)
16 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h"
18 namespace {
20 ////////////////////////////////////////////////////////////////////////////////
21 // BaseWindowFinder
23 // Base class used to locate a window. A subclass need only override
24 // ShouldStopIterating to determine when iteration should stop.
25 class BaseWindowFinder : public ui::EnumerateWindowsDelegate {
26 public:
27 explicit BaseWindowFinder(const std::set<aura::Window*>& ignore) {
28 std::set<aura::Window*>::iterator iter;
29 for (iter = ignore.begin(); iter != ignore.end(); iter++) {
30 XID xid = (*iter)->GetDispatcher()->host()->GetAcceleratedWidget();
31 ignore_.insert(xid);
35 virtual ~BaseWindowFinder() {}
37 protected:
38 // Returns true if |window| is in the ignore list.
39 bool ShouldIgnoreWindow(XID window) {
40 return (ignore_.find(window) != ignore_.end());
43 // Returns true if iteration should stop, false otherwise.
44 virtual bool ShouldStopIterating(XID window) OVERRIDE {
45 return false;
48 private:
49 std::set<XID> ignore_;
51 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder);
54 ////////////////////////////////////////////////////////////////////////////////
55 // TopMostFinder
57 // Helper class to determine if a particular point of a window is not obscured
58 // by another window.
59 class TopMostFinder : public BaseWindowFinder {
60 public:
61 // Returns true if |window| is not obscured by another window at the
62 // location |screen_loc|, not including the windows in |ignore|.
63 static bool IsTopMostWindowAtPoint(XID window,
64 const gfx::Point& screen_loc,
65 const std::set<aura::Window*>& ignore) {
66 TopMostFinder finder(window, screen_loc, ignore);
67 return finder.is_top_most_;
70 protected:
71 virtual bool ShouldStopIterating(XID window) OVERRIDE {
72 if (BaseWindowFinder::ShouldIgnoreWindow(window))
73 return false;
75 if (window == target_) {
76 // Window is topmost, stop iterating.
77 is_top_most_ = true;
78 return true;
81 if (!ui::IsWindowVisible(window)) {
82 // The window isn't visible, keep iterating.
83 return false;
86 // At this point we haven't found our target window, so this window is
87 // higher in the z-order than the target window. If this window contains
88 // the point, then we can stop the search now because this window is
89 // obscuring the target window at this point.
90 return ui::WindowContainsPoint(window, screen_loc_);
93 private:
94 TopMostFinder(XID window,
95 const gfx::Point& screen_loc,
96 const std::set<aura::Window*>& ignore)
97 : BaseWindowFinder(ignore),
98 target_(window),
99 screen_loc_(screen_loc),
100 is_top_most_(false) {
101 ui::EnumerateTopLevelWindows(this);
104 // The window we're looking for.
105 XID target_;
107 // Location of window to find.
108 gfx::Point screen_loc_;
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_;
114 DISALLOW_COPY_AND_ASSIGN(TopMostFinder);
117 ////////////////////////////////////////////////////////////////////////////////
118 // LocalProcessWindowFinder
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<aura::Window*>& ignore) {
128 LocalProcessWindowFinder finder(screen_loc, ignore);
129 if (finder.result_ &&
130 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc,
131 ignore)) {
132 return finder.result_;
134 return 0;
137 protected:
138 virtual bool ShouldStopIterating(XID window) OVERRIDE {
139 if (BaseWindowFinder::ShouldIgnoreWindow(window))
140 return false;
142 // Check if this window is in our process.
143 if (!aura::RootWindow::GetForAcceleratedWidget(window))
144 return false;
146 if (!ui::IsWindowVisible(window))
147 return false;
149 if (ui::WindowContainsPoint(window, screen_loc_)) {
150 result_ = window;
151 return true;
154 return false;
157 private:
158 LocalProcessWindowFinder(const gfx::Point& screen_loc,
159 const std::set<aura::Window*>& ignore)
160 : BaseWindowFinder(ignore),
161 screen_loc_(screen_loc),
162 result_(0) {
163 ui::EnumerateTopLevelWindows(this);
166 // Position of the mouse.
167 gfx::Point screen_loc_;
169 // The resulting window. This is initially null but set to true in
170 // ShouldStopIterating if an appropriate window is found.
171 XID result_;
173 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder);
176 } // namespace
178 // static
179 gfx::NativeView DockInfo::GetLocalProcessWindowAtPoint(
180 chrome::HostDesktopType host_desktop_type,
181 const gfx::Point& screen_point,
182 const std::set<gfx::NativeView>& ignore) {
183 TRACE_EVENT1("ui", "DockInfo::GetLocalProcessWindowAtPoint",
184 "screen_point", screen_point.ToString());
186 // The X11 server is the canonical state of what the window stacking order
187 // is.
188 XID xid =
189 LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore);
190 return views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid);
192 #else
193 // static
194 gfx::NativeView DockInfo::GetLocalProcessWindowAtPoint(
195 chrome::HostDesktopType host_desktop_type,
196 const gfx::Point& screen_point,
197 const std::set<gfx::NativeView>& ignore) {
199 // TODO(vignatti):
200 NOTIMPLEMENTED();
201 return NULL;
203 #endif
205 // static
206 DockInfo DockInfo::GetDockInfoAtPoint(chrome::HostDesktopType host_desktop_type,
207 const gfx::Point& screen_point,
208 const std::set<gfx::NativeView>& ignore) {
209 // TODO(beng):
210 NOTIMPLEMENTED();
211 return DockInfo();
214 bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const {
215 if (!window())
216 return false;
217 *bounds = window_->bounds();
218 return true;
221 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const {
222 window_->SetBounds(bounds);