| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/win/scoped_gdi_object.h" | 7 #include "base/win/scoped_gdi_object.h" |
| 8 #include "base/win/windows_version.h" | 8 #include "base/win/windows_version.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // | 21 // |
| 22 // A subclass need only override ShouldStopIterating to determine when | 22 // A subclass need only override ShouldStopIterating to determine when |
| 23 // iteration should stop. | 23 // iteration should stop. |
| 24 class BaseWindowFinder { | 24 class BaseWindowFinder { |
| 25 public: | 25 public: |
| 26 // Creates a BaseWindowFinder with the specified set of HWNDs to ignore. | 26 // Creates a BaseWindowFinder with the specified set of HWNDs to ignore. |
| 27 explicit BaseWindowFinder(const std::set<HWND>& ignore) : ignore_(ignore) {} | 27 explicit BaseWindowFinder(const std::set<HWND>& ignore) : ignore_(ignore) {} |
| 28 virtual ~BaseWindowFinder() {} | 28 virtual ~BaseWindowFinder() {} |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 // Returns true if iteration should stop, false if iteration should continue. | |
| 32 virtual bool ShouldStopIterating(HWND window) = 0; | |
| 33 | |
| 34 static BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { | 31 static BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { |
| 32 // Cast must match that in as_lparam(). |
| 35 BaseWindowFinder* finder = reinterpret_cast<BaseWindowFinder*>(lParam); | 33 BaseWindowFinder* finder = reinterpret_cast<BaseWindowFinder*>(lParam); |
| 36 if (finder->ignore_.find(hwnd) != finder->ignore_.end()) | 34 if (finder->ignore_.find(hwnd) != finder->ignore_.end()) |
| 37 return TRUE; | 35 return TRUE; |
| 38 | 36 |
| 39 return finder->ShouldStopIterating(hwnd) ? FALSE : TRUE; | 37 return finder->ShouldStopIterating(hwnd) ? FALSE : TRUE; |
| 40 } | 38 } |
| 41 | 39 |
| 40 LPARAM as_lparam() { |
| 41 // Cast must match that in WindowCallbackProc(). |
| 42 return reinterpret_cast<LPARAM>(static_cast<BaseWindowFinder*>(this)); |
| 43 } |
| 44 |
| 45 // Returns true if iteration should stop, false if iteration should continue. |
| 46 virtual bool ShouldStopIterating(HWND window) = 0; |
| 47 |
| 42 private: | 48 private: |
| 43 const std::set<HWND>& ignore_; | 49 const std::set<HWND>& ignore_; |
| 44 | 50 |
| 45 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder); | 51 DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder); |
| 46 }; | 52 }; |
| 47 | 53 |
| 48 // TopMostFinder -------------------------------------------------------------- | 54 // TopMostFinder -------------------------------------------------------------- |
| 49 | 55 |
| 50 // Helper class to determine if a particular point of a window is not obscured | 56 // Helper class to determine if a particular point of a window is not obscured |
| 51 // by another window. | 57 // by another window. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 117 |
| 112 private: | 118 private: |
| 113 TopMostFinder(HWND window, | 119 TopMostFinder(HWND window, |
| 114 const gfx::Point& screen_loc, | 120 const gfx::Point& screen_loc, |
| 115 const std::set<HWND>& ignore) | 121 const std::set<HWND>& ignore) |
| 116 : BaseWindowFinder(ignore), | 122 : BaseWindowFinder(ignore), |
| 117 target_(window), | 123 target_(window), |
| 118 screen_loc_(screen_loc), | 124 screen_loc_(screen_loc), |
| 119 is_top_most_(false), | 125 is_top_most_(false), |
| 120 tmp_region_(CreateRectRgn(0, 0, 0, 0)) { | 126 tmp_region_(CreateRectRgn(0, 0, 0, 0)) { |
| 121 EnumWindows(WindowCallbackProc, reinterpret_cast<LPARAM>(this)); | 127 EnumWindows(WindowCallbackProc, as_lparam()); |
| 122 } | 128 } |
| 123 | 129 |
| 124 // The window we're looking for. | 130 // The window we're looking for. |
| 125 HWND target_; | 131 HWND target_; |
| 126 | 132 |
| 127 // Location of window to find. | 133 // Location of window to find. |
| 128 gfx::Point screen_loc_; | 134 gfx::Point screen_loc_; |
| 129 | 135 |
| 130 // Is target_ the top most window? This is initially false but set to true | 136 // Is target_ the top most window? This is initially false but set to true |
| 131 // in ShouldStopIterating if target_ is passed in. | 137 // in ShouldStopIterating if target_ is passed in. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 176 } |
| 171 return false; | 177 return false; |
| 172 } | 178 } |
| 173 | 179 |
| 174 private: | 180 private: |
| 175 LocalProcessWindowFinder(const gfx::Point& screen_loc, | 181 LocalProcessWindowFinder(const gfx::Point& screen_loc, |
| 176 const std::set<HWND>& ignore) | 182 const std::set<HWND>& ignore) |
| 177 : BaseWindowFinder(ignore), | 183 : BaseWindowFinder(ignore), |
| 178 screen_loc_(screen_loc), | 184 screen_loc_(screen_loc), |
| 179 result_(NULL) { | 185 result_(NULL) { |
| 180 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, | 186 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam()); |
| 181 reinterpret_cast<LPARAM>(this)); | |
| 182 } | 187 } |
| 183 | 188 |
| 184 // Position of the mouse. | 189 // Position of the mouse. |
| 185 gfx::Point screen_loc_; | 190 gfx::Point screen_loc_; |
| 186 | 191 |
| 187 // The resulting window. This is initially null but set to true in | 192 // The resulting window. This is initially null but set to true in |
| 188 // ShouldStopIterating if an appropriate window is found. | 193 // ShouldStopIterating if an appropriate window is found. |
| 189 HWND result_; | 194 HWND result_; |
| 190 | 195 |
| 191 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder); | 196 DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 239 |
| 235 private: | 240 private: |
| 236 DockToWindowFinder(const gfx::Point& screen_loc, | 241 DockToWindowFinder(const gfx::Point& screen_loc, |
| 237 const std::set<HWND>& ignore) | 242 const std::set<HWND>& ignore) |
| 238 : BaseWindowFinder(ignore), | 243 : BaseWindowFinder(ignore), |
| 239 screen_loc_(screen_loc) { | 244 screen_loc_(screen_loc) { |
| 240 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint( | 245 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint( |
| 241 screen_loc); | 246 screen_loc); |
| 242 if (!work_area.IsEmpty()) { | 247 if (!work_area.IsEmpty()) { |
| 243 result_.set_monitor_bounds(work_area); | 248 result_.set_monitor_bounds(work_area); |
| 244 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, | 249 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam()); |
| 245 reinterpret_cast<LPARAM>(this)); | |
| 246 } | 250 } |
| 247 } | 251 } |
| 248 | 252 |
| 249 bool CheckPoint(HWND hwnd, int x, int y, DockInfo::Type type) { | 253 bool CheckPoint(HWND hwnd, int x, int y, DockInfo::Type type) { |
| 250 bool in_enable_area; | 254 bool in_enable_area; |
| 251 if (DockInfo::IsCloseToPoint(screen_loc_, x, y, &in_enable_area)) { | 255 if (DockInfo::IsCloseToPoint(screen_loc_, x, y, &in_enable_area)) { |
| 252 result_.set_in_enable_area(in_enable_area); | 256 result_.set_in_enable_area(in_enable_area); |
| 253 result_.set_window(hwnd); | 257 result_.set_window(hwnd); |
| 254 result_.set_type(type); | 258 result_.set_type(type); |
| 255 result_.set_hot_spot(gfx::Point(x, y)); | 259 result_.set_hot_spot(gfx::Point(x, y)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 325 |
| 322 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { | 326 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { |
| 323 if (IsZoomed(window())) { | 327 if (IsZoomed(window())) { |
| 324 // We're docking relative to another window, we need to make sure the | 328 // We're docking relative to another window, we need to make sure the |
| 325 // window we're docking to isn't maximized. | 329 // window we're docking to isn't maximized. |
| 326 ShowWindow(window(), SW_RESTORE | SW_SHOWNA); | 330 ShowWindow(window(), SW_RESTORE | SW_SHOWNA); |
| 327 } | 331 } |
| 328 SetWindowPos(window(), HWND_TOP, bounds.x(), bounds.y(), bounds.width(), | 332 SetWindowPos(window(), HWND_TOP, bounds.x(), bounds.y(), bounds.width(), |
| 329 bounds.height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER); | 333 bounds.height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER); |
| 330 } | 334 } |
| OLD | NEW |