| OLD | NEW |
| (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/tabs/dock_info.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/host_desktop.h" | |
| 8 #include "ui/aura/root_window.h" | |
| 9 #include "ui/aura/window.h" | |
| 10 #include "ui/base/x/x11_util.h" | |
| 11 | |
| 12 #if !defined(OS_CHROMEOS) | |
| 13 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" | |
| 14 #endif | |
| 15 | |
| 16 #if !defined(OS_CHROMEOS) | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 //////////////////////////////////////////////////////////////////////////////// | |
| 21 // BaseWindowFinder | |
| 22 // | |
| 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()->GetAcceleratedWidget(); | |
| 31 ignore_.insert(xid); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 virtual ~BaseWindowFinder() {} | |
| 36 | |
| 37 protected: | |
| 38 // Returns true if |window| is in the ignore list. | |
| 39 bool ShouldIgnoreWindow(XID window) { | |
| 40 return (ignore_.find(window) != ignore_.end()); | |
| 41 } | |
| 42 | |
| 43 // Returns true if iteration should stop, false otherwise. | |
| 44 virtual bool ShouldStopIterating(XID window) OVERRIDE { | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 std::set<XID> ignore_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder); | |
| 52 }; | |
| 53 | |
| 54 //////////////////////////////////////////////////////////////////////////////// | |
| 55 // TopMostFinder | |
| 56 // | |
| 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_; | |
| 68 } | |
| 69 | |
| 70 protected: | |
| 71 virtual bool ShouldStopIterating(XID window) OVERRIDE { | |
| 72 if (BaseWindowFinder::ShouldIgnoreWindow(window)) | |
| 73 return false; | |
| 74 | |
| 75 if (window == target_) { | |
| 76 // Window is topmost, stop iterating. | |
| 77 is_top_most_ = true; | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 if (!ui::IsWindowVisible(window)) { | |
| 82 // The window isn't visible, keep iterating. | |
| 83 return false; | |
| 84 } | |
| 85 | |
| 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_); | |
| 91 } | |
| 92 | |
| 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); | |
| 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<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_; | |
| 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 (!aura::RootWindow::GetForAcceleratedWidget(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<aura::Window*>& 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 // static | |
| 179 DockInfo DockInfo::GetDockInfoAtPoint(chrome::HostDesktopType host_desktop_type, | |
| 180 const gfx::Point& screen_point, | |
| 181 const std::set<gfx::NativeView>& ignore) { | |
| 182 // TODO(beng): | |
| 183 NOTIMPLEMENTED(); | |
| 184 return DockInfo(); | |
| 185 } | |
| 186 | |
| 187 // static | |
| 188 gfx::NativeView DockInfo::GetLocalProcessWindowAtPoint( | |
| 189 chrome::HostDesktopType host_desktop_type, | |
| 190 const gfx::Point& screen_point, | |
| 191 const std::set<gfx::NativeView>& ignore) { | |
| 192 // The X11 server is the canonical state of what the window stacking order | |
| 193 // is. | |
| 194 XID xid = | |
| 195 LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore); | |
| 196 return views::DesktopRootWindowHostX11::GetContentWindowForXID(xid); | |
| 197 } | |
| 198 | |
| 199 bool DockInfo::GetWindowBounds(gfx::Rect* bounds) const { | |
| 200 if (!window()) | |
| 201 return false; | |
| 202 *bounds = window_->bounds(); | |
| 203 return true; | |
| 204 } | |
| 205 | |
| 206 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { | |
| 207 window_->SetBounds(bounds); | |
| 208 } | |
| 209 | |
| 210 #endif | |
| OLD | NEW |