OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <atlbase.h> | |
8 #include <atlapp.h> | |
9 #include <atlmisc.h> | |
10 | |
11 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
12 #include "base/logging.h" | 8 #include "base/logging.h" |
13 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
14 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
15 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
16 #include "chrome/browser/views/frame/browser_view.h" | 12 #include "chrome/browser/views/frame/browser_view.h" |
17 #include "chrome/browser/views/tabs/tab.h" | 13 #include "chrome/browser/views/tabs/tab.h" |
18 | 14 |
19 namespace { | 15 namespace { |
20 | 16 |
21 // BaseWindowFinder ----------------------------------------------------------- | 17 // BaseWindowFinder ----------------------------------------------------------- |
22 | 18 |
23 // Base class used to locate a window. This is intended to be used with the | 19 // Base class used to locate a window. This is intended to be used with the |
24 // various win32 functions that iterate over windows. | 20 // various win32 functions that iterate over windows. |
25 // | 21 // |
26 // A subclass need only override ShouldStopIterating to determine when | 22 // A subclass need only override ShouldStopIterating to determine when |
27 // iteration should stop. | 23 // iteration should stop. |
28 class BaseWindowFinder { | 24 class BaseWindowFinder { |
29 public: | 25 public: |
30 // Creates a BaseWindowFinder with the specified set of HWNDs to ignore. | 26 // Creates a BaseWindowFinder with the specified set of HWNDs to ignore. |
31 BaseWindowFinder(const std::set<HWND>& ignore) : ignore_(ignore) {} | 27 explicit BaseWindowFinder(const std::set<HWND>& ignore) : ignore_(ignore) {} |
32 virtual ~BaseWindowFinder() {} | 28 virtual ~BaseWindowFinder() {} |
33 | 29 |
34 protected: | 30 protected: |
35 // Returns true if iteration should stop, false if iteration should continue. | 31 // Returns true if iteration should stop, false if iteration should continue. |
36 virtual bool ShouldStopIterating(HWND window) = 0; | 32 virtual bool ShouldStopIterating(HWND window) = 0; |
37 | 33 |
38 static BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { | 34 static BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { |
39 BaseWindowFinder* finder = reinterpret_cast<BaseWindowFinder*>(lParam); | 35 BaseWindowFinder* finder = reinterpret_cast<BaseWindowFinder*>(lParam); |
40 if (finder->ignore_.find(hwnd) != finder->ignore_.end()) | 36 if (finder->ignore_.find(hwnd) != finder->ignore_.end()) |
41 return TRUE; | 37 return TRUE; |
(...skipping 22 matching lines...) Expand all Loading... |
64 return finder.is_top_most_; | 60 return finder.is_top_most_; |
65 } | 61 } |
66 | 62 |
67 virtual bool ShouldStopIterating(HWND hwnd) { | 63 virtual bool ShouldStopIterating(HWND hwnd) { |
68 if (hwnd == target_) { | 64 if (hwnd == target_) { |
69 // Window is topmost, stop iterating. | 65 // Window is topmost, stop iterating. |
70 is_top_most_ = true; | 66 is_top_most_ = true; |
71 return true; | 67 return true; |
72 } | 68 } |
73 | 69 |
74 if (!::IsWindowVisible(hwnd)) { | 70 if (!IsWindowVisible(hwnd)) { |
75 // The window isn't visible, keep iterating. | 71 // The window isn't visible, keep iterating. |
76 return false; | 72 return false; |
77 } | 73 } |
78 | 74 |
79 CRect r; | 75 RECT r; |
80 if (!::GetWindowRect(hwnd, &r) || !r.PtInRect(screen_loc_.ToPOINT())) { | 76 if (!GetWindowRect(hwnd, &r) || !PtInRect(&r, screen_loc_.ToPOINT())) { |
81 // The window doesn't contain the point, keep iterating. | 77 // The window doesn't contain the point, keep iterating. |
82 return false; | 78 return false; |
83 } | 79 } |
84 | 80 |
85 // hwnd is at the point. Make sure the point is within the windows region. | 81 // hwnd is at the point. Make sure the point is within the windows region. |
86 if (GetWindowRgn(hwnd, tmp_region_.Get()) == ERROR) { | 82 if (GetWindowRgn(hwnd, tmp_region_.Get()) == ERROR) { |
87 // There's no region on the window and the window contains the point. Stop | 83 // There's no region on the window and the window contains the point. Stop |
88 // iterating. | 84 // iterating. |
89 return true; | 85 return true; |
90 } | 86 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (finder.result_ && | 134 if (finder.result_ && |
139 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc, | 135 TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc, |
140 ignore)) { | 136 ignore)) { |
141 return finder.result_; | 137 return finder.result_; |
142 } | 138 } |
143 return NULL; | 139 return NULL; |
144 } | 140 } |
145 | 141 |
146 protected: | 142 protected: |
147 virtual bool ShouldStopIterating(HWND hwnd) { | 143 virtual bool ShouldStopIterating(HWND hwnd) { |
148 CRect r; | 144 RECT r; |
149 if (::IsWindowVisible(hwnd) && ::GetWindowRect(hwnd, &r) && | 145 if (IsWindowVisible(hwnd) && GetWindowRect(hwnd, &r) && |
150 r.PtInRect(screen_loc_.ToPOINT())) { | 146 PtInRect(&r, screen_loc_.ToPOINT())) { |
151 result_ = hwnd; | 147 result_ = hwnd; |
152 return true; | 148 return true; |
153 } | 149 } |
154 return false; | 150 return false; |
155 } | 151 } |
156 | 152 |
157 private: | 153 private: |
158 LocalProcessWindowFinder(const gfx::Point& screen_loc, | 154 LocalProcessWindowFinder(const gfx::Point& screen_loc, |
159 const std::set<HWND>& ignore) | 155 const std::set<HWND>& ignore) |
160 : BaseWindowFinder(ignore), | 156 : BaseWindowFinder(ignore), |
(...skipping 28 matching lines...) Expand all Loading... |
189 finder.result_.hot_spot(), | 185 finder.result_.hot_spot(), |
190 ignore)) { | 186 ignore)) { |
191 finder.result_.set_type(DockInfo::NONE); | 187 finder.result_.set_type(DockInfo::NONE); |
192 } | 188 } |
193 return finder.result_; | 189 return finder.result_; |
194 } | 190 } |
195 | 191 |
196 protected: | 192 protected: |
197 virtual bool ShouldStopIterating(HWND hwnd) { | 193 virtual bool ShouldStopIterating(HWND hwnd) { |
198 BrowserView* window = BrowserView::GetBrowserViewForNativeWindow(hwnd); | 194 BrowserView* window = BrowserView::GetBrowserViewForNativeWindow(hwnd); |
199 CRect bounds; | 195 RECT bounds; |
200 if (!window || !::IsWindowVisible(hwnd) || | 196 if (!window || !IsWindowVisible(hwnd) || |
201 !::GetWindowRect(hwnd, &bounds)) { | 197 !GetWindowRect(hwnd, &bounds)) { |
202 return false; | 198 return false; |
203 } | 199 } |
204 | 200 |
205 // Check the three corners we allow docking to. We don't currently allow | 201 // Check the three corners we allow docking to. We don't currently allow |
206 // docking to top of window as it conflicts with docking to the tab strip. | 202 // docking to top of window as it conflicts with docking to the tab strip. |
207 if (CheckPoint(hwnd, bounds.left, (bounds.top + bounds.bottom) / 2, | 203 if (CheckPoint(hwnd, bounds.left, (bounds.top + bounds.bottom) / 2, |
208 DockInfo::LEFT_OF_WINDOW) || | 204 DockInfo::LEFT_OF_WINDOW) || |
209 CheckPoint(hwnd, bounds.right - 1, (bounds.top + bounds.bottom) / 2, | 205 CheckPoint(hwnd, bounds.right - 1, (bounds.top + bounds.bottom) / 2, |
210 DockInfo::RIGHT_OF_WINDOW) || | 206 DockInfo::RIGHT_OF_WINDOW) || |
211 CheckPoint(hwnd, (bounds.left + bounds.right) / 2, bounds.bottom - 1, | 207 CheckPoint(hwnd, (bounds.left + bounds.right) / 2, bounds.bottom - 1, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 *bounds = gfx::Rect(window_rect); | 299 *bounds = gfx::Rect(window_rect); |
304 return true; | 300 return true; |
305 } | 301 } |
306 | 302 |
307 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { | 303 void DockInfo::SizeOtherWindowTo(const gfx::Rect& bounds) const { |
308 if (IsZoomed(window())) { | 304 if (IsZoomed(window())) { |
309 // We're docking relative to another window, we need to make sure the | 305 // We're docking relative to another window, we need to make sure the |
310 // window we're docking to isn't maximized. | 306 // window we're docking to isn't maximized. |
311 ShowWindow(window(), SW_RESTORE | SW_SHOWNA); | 307 ShowWindow(window(), SW_RESTORE | SW_SHOWNA); |
312 } | 308 } |
313 ::SetWindowPos(window(), HWND_TOP, bounds.x(), bounds.y(), bounds.width(), | 309 SetWindowPos(window(), HWND_TOP, bounds.x(), bounds.y(), bounds.width(), |
314 bounds.height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER); | 310 bounds.height(), SWP_NOACTIVATE | SWP_NOOWNERZORDER); |
315 } | 311 } |
OLD | NEW |