| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 using views::View; | 33 using views::View; |
| 34 using web_modal::WebContentsModalDialogHost; | 34 using web_modal::WebContentsModalDialogHost; |
| 35 using web_modal::ModalDialogHostObserver; | 35 using web_modal::ModalDialogHostObserver; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // The visible height of the shadow above the tabs. Clicks in this area are | 39 // The visible height of the shadow above the tabs. Clicks in this area are |
| 40 // treated as clicks to the frame, rather than clicks to the tab. | 40 // treated as clicks to the frame, rather than clicks to the tab. |
| 41 const int kTabShadowSize = 2; | 41 const int kTabShadowSize = 2; |
| 42 // The number of pixels the metro switcher is offset from the right edge. | |
| 43 const int kWindowSwitcherOffsetX = 7; | |
| 44 // The number of pixels the constrained window should overlap the bottom | 42 // The number of pixels the constrained window should overlap the bottom |
| 45 // of the omnibox. | 43 // of the omnibox. |
| 46 const int kConstrainedWindowOverlap = 3; | 44 const int kConstrainedWindowOverlap = 3; |
| 47 | 45 |
| 48 // Combines View::ConvertPointToTarget and View::HitTest for a given |point|. | 46 // Combines View::ConvertPointToTarget and View::HitTest for a given |point|. |
| 49 // Converts |point| from |src| to |dst| and hit tests it against |dst|. The | 47 // Converts |point| from |src| to |dst| and hit tests it against |dst|. The |
| 50 // converted |point| can then be retrieved and used for additional tests. | 48 // converted |point| can then be retrieved and used for additional tests. |
| 51 bool ConvertedHitTest(views::View* src, views::View* dst, gfx::Point* point) { | 49 bool ConvertedHitTest(views::View* src, views::View* dst, gfx::Point* point) { |
| 52 DCHECK(src); | 50 DCHECK(src); |
| 53 DCHECK(dst); | 51 DCHECK(dst); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 287 |
| 290 // If the point's y coordinate is below the top of the toolbar and otherwise | 288 // If the point's y coordinate is below the top of the toolbar and otherwise |
| 291 // within the bounds of this view, the point is considered to be within the | 289 // within the bounds of this view, the point is considered to be within the |
| 292 // client area. | 290 // client area. |
| 293 gfx::Rect bv_bounds = browser_view_->bounds(); | 291 gfx::Rect bv_bounds = browser_view_->bounds(); |
| 294 bv_bounds.Offset(0, toolbar_->y()); | 292 bv_bounds.Offset(0, toolbar_->y()); |
| 295 bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); | 293 bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); |
| 296 if (bv_bounds.Contains(point)) | 294 if (bv_bounds.Contains(point)) |
| 297 return HTCLIENT; | 295 return HTCLIENT; |
| 298 | 296 |
| 299 // If the point is within the bounds of the window switcher button, the point | 297 // If the point's y coordinate is above the top of the toolbar, but not |
| 300 // is considered to be within the client area. | 298 // over the tabstrip (per previous checking in this function), then we |
| 301 views::View* window_switcher_button = delegate_->GetWindowSwitcherButton(); | 299 // consider it in the window caption (e.g. the area to the right of the |
| 302 if (window_switcher_button && window_switcher_button->visible()) { | 300 // tabstrip underneath the window controls). However, note that we DO NOT |
| 303 gfx::Point window_switcher_point(point_in_browser_view_coords); | 301 // return HTCAPTION here, because when the window is maximized the window |
| 304 views::View::ConvertPointToTarget(browser_view_, window_switcher_button, | 302 // controls will fall into this space (since the BrowserView is sized to |
| 305 &window_switcher_point); | 303 // entire size of the window at that point), and the HTCAPTION value will |
| 306 if (window_switcher_button->HitTestPoint(window_switcher_point)) | 304 // cause the window controls not to work. So we return HTNOWHERE so that the |
| 307 return HTCLIENT; | 305 // caller will hit-test the window controls before finally falling back to |
| 308 } | 306 // HTCAPTION. |
| 309 | |
| 310 // If the point's y coordinate is above the top of the toolbar, but neither | |
| 311 // over the tabstrip nor over the window switcher button (per previous | |
| 312 // checking in this function), then we consider it in the window caption | |
| 313 // (e.g. the area to the right of the tabstrip underneath the window | |
| 314 // controls). However, note that we DO NOT return HTCAPTION here, because | |
| 315 // when the window is maximized the window controls will fall into this | |
| 316 // space (since the BrowserView is sized to entire size of the window at that | |
| 317 // point), and the HTCAPTION value will cause the window controls not to work. | |
| 318 // So we return HTNOWHERE so that the caller will hit-test the window controls | |
| 319 // before finally falling back to HTCAPTION. | |
| 320 bv_bounds = browser_view_->bounds(); | 307 bv_bounds = browser_view_->bounds(); |
| 321 bv_bounds.set_height(toolbar_->y()); | 308 bv_bounds.set_height(toolbar_->y()); |
| 322 if (bv_bounds.Contains(point)) | 309 if (bv_bounds.Contains(point)) |
| 323 return HTNOWHERE; | 310 return HTNOWHERE; |
| 324 | 311 |
| 325 // If the point is somewhere else, delegate to the default implementation. | 312 // If the point is somewhere else, delegate to the default implementation. |
| 326 return browser_view_->views::ClientView::NonClientHitTest(point); | 313 return browser_view_->views::ClientView::NonClientHitTest(point); |
| 327 } | 314 } |
| 328 | 315 |
| 329 ////////////////////////////////////////////////////////////////////////////// | 316 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 tab_strip_->SetVisible(false); | 382 tab_strip_->SetVisible(false); |
| 396 tab_strip_->SetBounds(0, 0, 0, 0); | 383 tab_strip_->SetBounds(0, 0, 0, 0); |
| 397 return top; | 384 return top; |
| 398 } | 385 } |
| 399 // This retrieves the bounds for the tab strip based on whether or not we show | 386 // This retrieves the bounds for the tab strip based on whether or not we show |
| 400 // anything to the left of it, like the incognito avatar. | 387 // anything to the left of it, like the incognito avatar. |
| 401 gfx::Rect tabstrip_bounds(delegate_->GetBoundsForTabStripInBrowserView()); | 388 gfx::Rect tabstrip_bounds(delegate_->GetBoundsForTabStripInBrowserView()); |
| 402 | 389 |
| 403 tab_strip_->SetVisible(true); | 390 tab_strip_->SetVisible(true); |
| 404 tab_strip_->SetBoundsRect(tabstrip_bounds); | 391 tab_strip_->SetBoundsRect(tabstrip_bounds); |
| 405 int bottom = tabstrip_bounds.bottom(); | |
| 406 | 392 |
| 407 // The metro window switcher sits at the far right edge of the tabstrip | 393 return tabstrip_bounds.bottom(); |
| 408 // a |kWindowSwitcherOffsetX| pixels from the right edge. | |
| 409 // Only visible if there is more than one type of window to switch between. | |
| 410 // TODO(mad): update this code when more window types than just incognito | |
| 411 // and regular are available. | |
| 412 views::View* switcher_button = delegate_->GetWindowSwitcherButton(); | |
| 413 if (switcher_button) { | |
| 414 if (browser()->profile()->HasOffTheRecordProfile() && | |
| 415 chrome::FindBrowserWithProfile( | |
| 416 browser()->profile()->GetOriginalProfile(), | |
| 417 browser()->host_desktop_type()) != NULL) { | |
| 418 switcher_button->SetVisible(true); | |
| 419 int width = browser_view_->width(); | |
| 420 gfx::Size ps = switcher_button->GetPreferredSize(); | |
| 421 if (width > ps.width()) { | |
| 422 switcher_button->SetBounds(width - ps.width() - kWindowSwitcherOffsetX, | |
| 423 0, | |
| 424 ps.width(), | |
| 425 ps.height()); | |
| 426 } | |
| 427 } else { | |
| 428 // We hide the button if the incognito profile is not alive. | |
| 429 // Note that Layout() is not called to all browser windows automatically | |
| 430 // when a profile goes away but we rely in the metro_driver.dll to call | |
| 431 // ::SetWindowPos( , .. SWP_SHOWWINDOW) which causes this function to | |
| 432 // be called again. This works both in showing or hidding the button. | |
| 433 switcher_button->SetVisible(false); | |
| 434 } | |
| 435 } | |
| 436 | |
| 437 return bottom; | |
| 438 } | 394 } |
| 439 | 395 |
| 440 int BrowserViewLayout::LayoutToolbar(int top) { | 396 int BrowserViewLayout::LayoutToolbar(int top) { |
| 441 int browser_view_width = vertical_layout_rect_.width(); | 397 int browser_view_width = vertical_layout_rect_.width(); |
| 442 bool toolbar_visible = delegate_->IsToolbarVisible(); | 398 bool toolbar_visible = delegate_->IsToolbarVisible(); |
| 443 int y = top; | 399 int y = top; |
| 444 y -= (toolbar_visible && delegate_->IsTabStripVisible()) ? | 400 y -= (toolbar_visible && delegate_->IsTabStripVisible()) ? |
| 445 kToolbarTabStripVerticalOverlap : 0; | 401 kToolbarTabStripVerticalOverlap : 0; |
| 446 int height = toolbar_visible ? toolbar_->GetPreferredSize().height() : 0; | 402 int height = toolbar_visible ? toolbar_->GetPreferredSize().height() : 0; |
| 447 toolbar_->SetVisible(toolbar_visible); | 403 toolbar_->SetVisible(toolbar_visible); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 return bottom; | 540 return bottom; |
| 585 } | 541 } |
| 586 | 542 |
| 587 bool BrowserViewLayout::InfobarVisible() const { | 543 bool BrowserViewLayout::InfobarVisible() const { |
| 588 // Cast to a views::View to access GetPreferredSize(). | 544 // Cast to a views::View to access GetPreferredSize(). |
| 589 views::View* infobar_container = infobar_container_; | 545 views::View* infobar_container = infobar_container_; |
| 590 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 546 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 591 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 547 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 592 (infobar_container->GetPreferredSize().height() != 0); | 548 (infobar_container->GetPreferredSize().height() != 0); |
| 593 } | 549 } |
| OLD | NEW |