| 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/views/constrained_window_impl.h" | 5 #include "chrome/browser/views/constrained_window_impl.h" |
| 6 | 6 |
| 7 #include "base/gfx/rect.h" | 7 #include "base/gfx/rect.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/app/theme/theme_resources.h" | 9 #include "chrome/app/theme/theme_resources.h" |
| 10 #include "chrome/browser/tab_contents.h" | 10 #include "chrome/browser/tab_contents.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 virtual gfx::Size CalculateWindowSizeForClientSize(int width, | 210 virtual gfx::Size CalculateWindowSizeForClientSize(int width, |
| 211 int height) const; | 211 int height) const; |
| 212 virtual CPoint GetSystemMenuPoint() const; | 212 virtual CPoint GetSystemMenuPoint() const; |
| 213 virtual int NonClientHitTest(const gfx::Point& point); | 213 virtual int NonClientHitTest(const gfx::Point& point); |
| 214 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); | 214 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); |
| 215 virtual void EnableClose(bool enable); | 215 virtual void EnableClose(bool enable); |
| 216 | 216 |
| 217 // Overridden from ChromeViews::View: | 217 // Overridden from ChromeViews::View: |
| 218 virtual void Paint(ChromeCanvas* canvas); | 218 virtual void Paint(ChromeCanvas* canvas); |
| 219 virtual void Layout(); | 219 virtual void Layout(); |
| 220 virtual void GetPreferredSize(CSize* out); | 220 virtual gfx::Size GetPreferredSize(); |
| 221 virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); | 221 virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); |
| 222 | 222 |
| 223 // Overridden from ChromeViews::BaseButton::ButtonListener: | 223 // Overridden from ChromeViews::BaseButton::ButtonListener: |
| 224 virtual void ButtonPressed(ChromeViews::BaseButton* sender); | 224 virtual void ButtonPressed(ChromeViews::BaseButton* sender); |
| 225 | 225 |
| 226 // Overridden from LocationBarView::Delegate: | 226 // Overridden from LocationBarView::Delegate: |
| 227 virtual TabContents* GetTabContents(); | 227 virtual TabContents* GetTabContents(); |
| 228 virtual void OnInputInProgress(bool in_progress); | 228 virtual void OnInputInProgress(bool in_progress); |
| 229 | 229 |
| 230 // Updates the current throbber animation frame; called from the | 230 // Updates the current throbber animation frame; called from the |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } else { | 418 } else { |
| 419 height = kNoTitleTopSpacing; | 419 height = kNoTitleTopSpacing; |
| 420 } | 420 } |
| 421 | 421 |
| 422 return height; | 422 return height; |
| 423 } | 423 } |
| 424 | 424 |
| 425 int ConstrainedWindowNonClientView::CalculateNonClientHeight( | 425 int ConstrainedWindowNonClientView::CalculateNonClientHeight( |
| 426 bool with_url_field) const { | 426 bool with_url_field) const { |
| 427 int r = CalculateTitlebarHeight(); | 427 int r = CalculateTitlebarHeight(); |
| 428 | 428 if (with_url_field) |
| 429 if (with_url_field) { | 429 r += location_bar_->GetPreferredSize().height(); |
| 430 CSize s; | |
| 431 location_bar_->GetPreferredSize(&s); | |
| 432 r += s.cy; | |
| 433 } | |
| 434 return r; | 430 return r; |
| 435 } | 431 } |
| 436 | 432 |
| 437 gfx::Rect ConstrainedWindowNonClientView::CalculateWindowBoundsForClientBounds( | 433 gfx::Rect ConstrainedWindowNonClientView::CalculateWindowBoundsForClientBounds( |
| 438 const gfx::Rect& client_bounds, | 434 const gfx::Rect& client_bounds, |
| 439 bool with_url_field) const { | 435 bool with_url_field) const { |
| 440 int non_client_height = CalculateNonClientHeight(with_url_field); | 436 int non_client_height = CalculateNonClientHeight(with_url_field); |
| 441 gfx::Rect window_bounds = client_bounds; | 437 gfx::Rect window_bounds = client_bounds; |
| 442 window_bounds.set_width( | 438 window_bounds.set_width( |
| 443 window_bounds.width() + 2 * kWindowHorizontalBorderSize); | 439 window_bounds.width() + 2 * kWindowHorizontalBorderSize); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 561 } |
| 566 | 562 |
| 567 void ConstrainedWindowNonClientView::Layout() { | 563 void ConstrainedWindowNonClientView::Layout() { |
| 568 bool should_display_url_field = false; | 564 bool should_display_url_field = false; |
| 569 if (location_bar_) { | 565 if (location_bar_) { |
| 570 should_display_url_field = ShouldDisplayURLField(); | 566 should_display_url_field = ShouldDisplayURLField(); |
| 571 location_bar_->SetVisible(should_display_url_field); | 567 location_bar_->SetVisible(should_display_url_field); |
| 572 } | 568 } |
| 573 | 569 |
| 574 int location_bar_height = 0; | 570 int location_bar_height = 0; |
| 575 CSize ps; | 571 gfx::Size ps; |
| 576 if (should_display_url_field) { | 572 if (should_display_url_field) { |
| 577 location_bar_->GetPreferredSize(&ps); | 573 ps = location_bar_->GetPreferredSize(); |
| 578 location_bar_height = ps.cy; | 574 location_bar_height = ps.height(); |
| 579 } | 575 } |
| 580 | 576 |
| 581 close_button_->GetPreferredSize(&ps); | 577 ps = close_button_->GetPreferredSize(); |
| 582 close_button_->SetBounds(width() - ps.cx - kWindowControlsRightOffset, | 578 close_button_->SetBounds(width() - ps.width() - kWindowControlsRightOffset, |
| 583 kWindowControlsTopOffset, ps.cx, ps.cy); | 579 kWindowControlsTopOffset, ps.width(), ps.height()); |
| 584 | 580 |
| 585 int titlebar_height = CalculateTitlebarHeight(); | 581 int titlebar_height = CalculateTitlebarHeight(); |
| 586 if (window_delegate_) { | 582 if (window_delegate_) { |
| 587 if (show_throbber_) { | 583 if (show_throbber_) { |
| 588 int icon_y = (titlebar_height - kWindowIconSize) / 2; | 584 int icon_y = (titlebar_height - kWindowIconSize) / 2; |
| 589 icon_bounds_.SetRect(kWindowLeftSpacing, icon_y, 0, 0); | 585 icon_bounds_.SetRect(kWindowLeftSpacing, icon_y, 0, 0); |
| 590 icon_bounds_.set_width(kWindowIconSize); | 586 icon_bounds_.set_width(kWindowIconSize); |
| 591 icon_bounds_.set_height(kWindowIconSize); | 587 icon_bounds_.set_height(kWindowIconSize); |
| 592 } else { | 588 } else { |
| 593 icon_bounds_.SetRect(0, 0, 0, 0); | 589 icon_bounds_.SetRect(0, 0, 0, 0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 613 location_bar_->SetBounds(client_bounds_.x() - kLocationBarOffset, | 609 location_bar_->SetBounds(client_bounds_.x() - kLocationBarOffset, |
| 614 client_bounds_.y() - location_bar_height - | 610 client_bounds_.y() - location_bar_height - |
| 615 kLocationBarSpacing, | 611 kLocationBarSpacing, |
| 616 client_bounds_.width() + kLocationBarOffset * 2, | 612 client_bounds_.width() + kLocationBarOffset * 2, |
| 617 location_bar_height); | 613 location_bar_height); |
| 618 location_bar_->Layout(); | 614 location_bar_->Layout(); |
| 619 } | 615 } |
| 620 container_->client_view()->SetBounds(client_bounds_.ToRECT()); | 616 container_->client_view()->SetBounds(client_bounds_.ToRECT()); |
| 621 } | 617 } |
| 622 | 618 |
| 623 void ConstrainedWindowNonClientView::GetPreferredSize(CSize* out) { | 619 gfx::Size ConstrainedWindowNonClientView::GetPreferredSize() { |
| 624 DCHECK(out); | 620 gfx::Size prefsize = container_->client_view()->GetPreferredSize(); |
| 625 container_->client_view()->GetPreferredSize(out); | 621 prefsize.Enlarge(2 * kWindowHorizontalBorderSize, |
| 626 out->cx += 2 * kWindowHorizontalBorderSize; | 622 CalculateNonClientHeight(ShouldDisplayURLField()) + |
| 627 out->cy += CalculateNonClientHeight(ShouldDisplayURLField()) + | 623 kWindowVerticalBorderSize); |
| 628 kWindowVerticalBorderSize; | 624 return prefsize; |
| 629 } | 625 } |
| 630 | 626 |
| 631 void ConstrainedWindowNonClientView::ViewHierarchyChanged(bool is_add, | 627 void ConstrainedWindowNonClientView::ViewHierarchyChanged(bool is_add, |
| 632 View *parent, | 628 View *parent, |
| 633 View *child) { | 629 View *child) { |
| 634 if (is_add && GetViewContainer()) { | 630 if (is_add && GetViewContainer()) { |
| 635 // Add our Client View as we are added to the ViewContainer so that if we | 631 // Add our Client View as we are added to the ViewContainer so that if we |
| 636 // are subsequently resized all the parent-child relationships are | 632 // are subsequently resized all the parent-child relationships are |
| 637 // established. | 633 // established. |
| 638 if (is_add && GetViewContainer() && child == this) | 634 if (is_add && GetViewContainer() && child == this) |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 initial_bounds, | 1371 initial_bounds, |
| 1376 parent->delegate()->ShouldDisplayURLField()); | 1372 parent->delegate()->ShouldDisplayURLField()); |
| 1377 | 1373 |
| 1378 window->InitSizeForContents(window_bounds); | 1374 window->InitSizeForContents(window_bounds); |
| 1379 | 1375 |
| 1380 // This is a constrained popup window and thus we need to animate it in. | 1376 // This is a constrained popup window and thus we need to animate it in. |
| 1381 window->StartSuppressedAnimation(); | 1377 window->StartSuppressedAnimation(); |
| 1382 | 1378 |
| 1383 return window; | 1379 return window; |
| 1384 } | 1380 } |
| OLD | NEW |