OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/views/frame/browser_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
6 | 6 |
7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // Finally decrease the width of the bounding box by the width of | 240 // Finally decrease the width of the bounding box by the width of |
241 // the vertical scroll bar. | 241 // the vertical scroll bar. |
242 int scrollbar_width = gfx::scrollbar_size(); | 242 int scrollbar_width = gfx::scrollbar_size(); |
243 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); | 243 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); |
244 if (base::i18n::IsRTL()) | 244 if (base::i18n::IsRTL()) |
245 bounding_box.set_x(bounding_box.x() + scrollbar_width); | 245 bounding_box.set_x(bounding_box.x() + scrollbar_width); |
246 | 246 |
247 return bounding_box; | 247 return bounding_box; |
248 } | 248 } |
249 | 249 |
250 bool BrowserViewLayout::IsPositionInWindowCaption( | |
251 const gfx::Point& point) { | |
252 // Tab strip may transiently have no parent between the RemoveChildView() and | |
253 // AddChildView() caused by reparenting during an immersive mode reveal. | |
254 // During this window report that the point didn't hit a tab. | |
255 if (!tab_strip_->parent()) | |
256 return true; | |
257 gfx::Point tabstrip_point(point); | |
258 views::View::ConvertPointToTarget(browser_view_, tab_strip_, &tabstrip_point); | |
259 return tab_strip_->IsPositionInWindowCaption(tabstrip_point); | |
260 } | |
261 | |
262 int BrowserViewLayout::NonClientHitTest( | 250 int BrowserViewLayout::NonClientHitTest( |
263 const gfx::Point& point) { | 251 const gfx::Point& point) const { |
264 // Since the TabStrip only renders in some parts of the top of the window, | 252 // Since the TabStrip only renders in some parts of the top of the window, |
265 // the un-obscured area is considered to be part of the non-client caption | 253 // the un-obscured area is considered to be part of the non-client caption |
266 // area of the window. So we need to treat hit-tests in these regions as | 254 // area of the window. So we need to treat hit-tests in these regions as |
267 // hit-tests of the titlebar. | 255 // hit-tests of the titlebar. |
268 | 256 |
269 views::View* parent = browser_view_->parent(); | 257 views::View* parent = browser_view_->parent(); |
270 | 258 |
271 gfx::Point point_in_browser_view_coords(point); | 259 gfx::Point point_in_browser_view_coords(point); |
272 views::View::ConvertPointToTarget( | 260 views::View::ConvertPointToTarget( |
273 parent, browser_view_, &point_in_browser_view_coords); | 261 parent, browser_view_, &point_in_browser_view_coords); |
274 gfx::Point test_point(point); | 262 gfx::Point test_point(point); |
275 | 263 |
276 // Determine if the TabStrip exists and is capable of being clicked on. We | 264 // Determine if the TabStrip exists and is capable of being clicked on. We |
277 // might be a popup window without a TabStrip. | 265 // might be a popup window without a TabStrip. |
278 if (browser_view_->IsTabStripVisible()) { | 266 if (browser_view_->IsTabStripVisible()) { |
279 // See if the mouse pointer is within the bounds of the TabStrip. | 267 // See if the mouse pointer is within the bounds of the TabStrip. |
280 if (ConvertedHitTest(parent, tab_strip_, &test_point)) { | 268 if (ConvertedHitTest(parent, tab_strip_, &test_point)) { |
281 if (tab_strip_->IsPositionInWindowCaption(test_point)) | 269 if (tab_strip_->IsPositionInWindowCaption(test_point)) |
282 return HTCAPTION; | 270 return HTCAPTION; |
283 return HTCLIENT; | 271 return HTCLIENT; |
284 } | 272 } |
285 | 273 |
286 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty | 274 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty |
287 // starved of dragable area, let's give it to window dragging (this also | 275 // starved of dragable area, let's give it to window dragging (this also |
288 // makes sense visually). | 276 // makes sense visually). |
289 if (!browser_view_->IsMaximized() && | 277 if (!(browser_view_->IsMaximized() || browser_view_->IsFullscreen()) && |
290 (point_in_browser_view_coords.y() < | 278 (point_in_browser_view_coords.y() < |
291 (tab_strip_->y() + kTabShadowSize))) { | 279 (tab_strip_->y() + kTabShadowSize))) { |
292 // We return HTNOWHERE as this is a signal to our containing | 280 // We return HTNOWHERE as this is a signal to our containing |
293 // NonClientView that it should figure out what the correct hit-test | 281 // NonClientView that it should figure out what the correct hit-test |
294 // code is given the mouse position... | 282 // code is given the mouse position... |
295 return HTNOWHERE; | 283 return HTNOWHERE; |
296 } | 284 } |
297 } | 285 } |
298 | 286 |
299 // If the point's y coordinate is below the top of the toolbar and otherwise | 287 // If the point's y coordinate is below the top of the toolbar and otherwise |
300 // within the bounds of this view, the point is considered to be within the | 288 // within the bounds of this view, the point is considered to be within the |
301 // client area. | 289 // client area. |
302 gfx::Rect bv_bounds = browser_view_->bounds(); | 290 gfx::Rect bv_bounds = browser_view_->bounds(); |
303 bv_bounds.Offset(0, toolbar_->y()); | 291 bv_bounds.Offset(0, toolbar_->y()); |
304 bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); | 292 bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); |
305 if (bv_bounds.Contains(point)) | 293 if (bv_bounds.Contains(point)) |
306 return HTCLIENT; | 294 return HTCLIENT; |
307 | 295 |
308 // If the point's y coordinate is above the top of the toolbar, but not in | 296 // If the point is within the bounds of the window switcher button, the point |
309 // the tabstrip (per previous checking in this function), then we consider it | 297 // is considered to be within the client area. |
310 // in the window caption (e.g. the area to the right of the tabstrip | 298 views::View* window_switcher_button = delegate_->GetWindowSwitcherButton(); |
311 // underneath the window controls). However, note that we DO NOT return | 299 if (window_switcher_button) { |
312 // HTCAPTION here, because when the window is maximized the window controls | 300 gfx::Point window_switcher_point(point_in_browser_view_coords); |
313 // will fall into this space (since the BrowserView is sized to entire size | 301 views::View::ConvertPointToTarget(browser_view_, window_switcher_button, |
314 // of the window at that point), and the HTCAPTION value will cause the | 302 &window_switcher_point); |
315 // window controls not to work. So we return HTNOWHERE so that the caller | 303 if (window_switcher_button->HitTestPoint(window_switcher_point)) |
316 // will hit-test the window controls before finally falling back to | 304 return HTCLIENT; |
317 // HTCAPTION. | 305 } |
| 306 |
| 307 // If the point's y coordinate is above the top of the toolbar, but neither |
| 308 // over the tabstrip nor over the window switcher button (per previous |
| 309 // checking in this function), then we consider it in the window caption |
| 310 // (e.g. the area to the right of the tabstrip underneath the window |
| 311 // controls). However, note that we DO NOT return HTCAPTION here, because |
| 312 // when the window is maximized the window controls will fall into this |
| 313 // space (since the BrowserView is sized to entire size of the window at that |
| 314 // point), and the HTCAPTION value will cause the window controls not to work. |
| 315 // So we return HTNOWHERE so that the caller will hit-test the window controls |
| 316 // before finally falling back to HTCAPTION. |
318 bv_bounds = browser_view_->bounds(); | 317 bv_bounds = browser_view_->bounds(); |
319 bv_bounds.set_height(toolbar_->y()); | 318 bv_bounds.set_height(toolbar_->y()); |
320 if (bv_bounds.Contains(point)) | 319 if (bv_bounds.Contains(point)) |
321 return HTNOWHERE; | 320 return HTNOWHERE; |
322 | 321 |
323 // If the point is somewhere else, delegate to the default implementation. | 322 // If the point is somewhere else, delegate to the default implementation. |
324 return browser_view_->views::ClientView::NonClientHitTest(point); | 323 return browser_view_->views::ClientView::NonClientHitTest(point); |
325 } | 324 } |
326 | 325 |
327 ////////////////////////////////////////////////////////////////////////////// | 326 ////////////////////////////////////////////////////////////////////////////// |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 return bottom; | 640 return bottom; |
642 } | 641 } |
643 | 642 |
644 bool BrowserViewLayout::InfobarVisible() const { | 643 bool BrowserViewLayout::InfobarVisible() const { |
645 // Cast to a views::View to access GetPreferredSize(). | 644 // Cast to a views::View to access GetPreferredSize(). |
646 views::View* infobar_container = infobar_container_; | 645 views::View* infobar_container = infobar_container_; |
647 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 646 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
648 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 647 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
649 (infobar_container->GetPreferredSize().height() != 0); | 648 (infobar_container->GetPreferredSize().height() != 0); |
650 } | 649 } |
OLD | NEW |