Commit 8e6821be authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Better integration between View and LayoutManager.

Views now rely on layout manager for both preferred and minimum size,
and layout managers can be notified when a view's layout is invalidated.

Change-Id: I189eab4bf1ab4369db0d7ca5391b432ac3424fcc
Reviewed-on: https://chromium-review.googlesource.com/c/1351967
Commit-Queue: Dana Fried <dfried@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611507}
parent c55c540a
...@@ -2275,7 +2275,7 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { ...@@ -2275,7 +2275,7 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) {
} }
gfx::Size BrowserView::GetMinimumSize() const { gfx::Size BrowserView::GetMinimumSize() const {
return GetBrowserViewLayout()->GetMinimumSize(); return GetBrowserViewLayout()->GetMinimumSize(this);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/views/frame/browser_view_layout.h" #include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include <algorithm>
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -168,7 +170,7 @@ WebContentsModalDialogHost* ...@@ -168,7 +170,7 @@ WebContentsModalDialogHost*
return dialog_host_.get(); return dialog_host_.get();
} }
gfx::Size BrowserViewLayout::GetMinimumSize() { gfx::Size BrowserViewLayout::GetMinimumSize(const views::View* host) const {
gfx::Size tabstrip_size( gfx::Size tabstrip_size(
browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ?
tab_strip_->GetMinimumSize() : gfx::Size()); tab_strip_->GetMinimumSize() : gfx::Size());
...@@ -184,7 +186,7 @@ gfx::Size BrowserViewLayout::GetMinimumSize() { ...@@ -184,7 +186,7 @@ gfx::Size BrowserViewLayout::GetMinimumSize() {
bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap()); bookmark_bar_size.Enlarge(0, -bookmark_bar_->GetToolbarOverlap());
} }
gfx::Size infobar_container_size(infobar_container_->GetMinimumSize()); gfx::Size infobar_container_size(infobar_container_->GetMinimumSize());
// TODO: Adjust the minimum height for the find bar. // TODO(pkotwicz): Adjust the minimum height for the find bar.
gfx::Size contents_size(contents_container_->GetMinimumSize()); gfx::Size contents_size(contents_container_->GetMinimumSize());
// Prevent having a 0x0 sized-contents as this can allow the window to be // Prevent having a 0x0 sized-contents as this can allow the window to be
......
...@@ -28,6 +28,7 @@ class Size; ...@@ -28,6 +28,7 @@ class Size;
namespace views { namespace views {
class ClientView; class ClientView;
class View;
} }
namespace web_modal { namespace web_modal {
...@@ -66,9 +67,6 @@ class BrowserViewLayout : public views::LayoutManager { ...@@ -66,9 +67,6 @@ class BrowserViewLayout : public views::LayoutManager {
web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost(); web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost();
// Returns the minimum size of the browser view.
gfx::Size GetMinimumSize();
// Returns the bounding box, in widget coordinates, for the find bar. // Returns the bounding box, in widget coordinates, for the find bar.
gfx::Rect GetFindBarBoundingBox() const; gfx::Rect GetFindBarBoundingBox() const;
...@@ -80,6 +78,7 @@ class BrowserViewLayout : public views::LayoutManager { ...@@ -80,6 +78,7 @@ class BrowserViewLayout : public views::LayoutManager {
// views::LayoutManager overrides: // views::LayoutManager overrides:
void Layout(views::View* host) override; void Layout(views::View* host) override;
gfx::Size GetMinimumSize(const views::View* host) const override;
gfx::Size GetPreferredSize(const views::View* host) const override; gfx::Size GetPreferredSize(const views::View* host) const override;
// Returns true if an infobar is showing. // Returns true if an infobar is showing.
...@@ -92,6 +91,7 @@ class BrowserViewLayout : public views::LayoutManager { ...@@ -92,6 +91,7 @@ class BrowserViewLayout : public views::LayoutManager {
class WebContentsModalDialogHostViews; class WebContentsModalDialogHostViews;
Browser* browser() { return browser_; } Browser* browser() { return browser_; }
const Browser* browser() const { return browser_; }
// Layout the following controls, starting at |top|, returns the coordinate // Layout the following controls, starting at |top|, returns the coordinate
// of the bottom of the control, for laying out the next control. // of the bottom of the control, for laying out the next control.
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
#include <algorithm>
#include <utility>
#include "build/build_config.h" #include "build/build_config.h"
#include "build/buildflag.h" #include "build/buildflag.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
...@@ -213,7 +216,7 @@ void OpaqueBrowserFrameView::UpdateThrobber(bool running) { ...@@ -213,7 +216,7 @@ void OpaqueBrowserFrameView::UpdateThrobber(bool running) {
} }
gfx::Size OpaqueBrowserFrameView::GetMinimumSize() const { gfx::Size OpaqueBrowserFrameView::GetMinimumSize() const {
return layout_->GetMinimumSize(width()); return layout_->GetMinimumSize(this);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
#include <algorithm>
#include <string>
#include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/adapters.h" #include "base/containers/adapters.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -93,7 +97,7 @@ gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( ...@@ -93,7 +97,7 @@ gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip(
} }
gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize(
int available_width) const { const views::View* host) const {
gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); gfx::Size min_size = delegate_->GetBrowserViewMinimumSize();
int border_thickness = FrameBorderThickness(false); int border_thickness = FrameBorderThickness(false);
min_size.Enlarge(2 * border_thickness, min_size.Enlarge(2 * border_thickness,
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_ #define CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/frame_button_display_types.h" #include "chrome/browser/ui/frame_button_display_types.h"
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
...@@ -52,8 +54,6 @@ class OpaqueBrowserFrameViewLayout : public views::LayoutManager { ...@@ -52,8 +54,6 @@ class OpaqueBrowserFrameViewLayout : public views::LayoutManager {
gfx::Rect GetBoundsForTabStrip(const gfx::Size& tabstrip_preferred_size, gfx::Rect GetBoundsForTabStrip(const gfx::Size& tabstrip_preferred_size,
int total_width) const; int total_width) const;
gfx::Size GetMinimumSize(int available_width) const;
// Returns the bounds of the window required to display the content area at // Returns the bounds of the window required to display the content area at
// the specified bounds. // the specified bounds.
gfx::Rect GetWindowBoundsForClientBounds( gfx::Rect GetWindowBoundsForClientBounds(
...@@ -128,6 +128,11 @@ class OpaqueBrowserFrameViewLayout : public views::LayoutManager { ...@@ -128,6 +128,11 @@ class OpaqueBrowserFrameViewLayout : public views::LayoutManager {
// Returns the extra thickness of the area above the tabs. // Returns the extra thickness of the area above the tabs.
int GetNonClientRestoredExtraThickness() const; int GetNonClientRestoredExtraThickness() const;
// views::LayoutManager:
// Called explicitly from OpaqueBrowserFrameView so we can't group it with
// the other overrides.
gfx::Size GetMinimumSize(const views::View* host) const override;
protected: protected:
// Whether a specific button should be inserted on the leading or trailing // Whether a specific button should be inserted on the leading or trailing
// side. // side.
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -266,7 +270,7 @@ class OpaqueBrowserFrameViewLayoutTest : public ChromeViewsTestBase { ...@@ -266,7 +270,7 @@ class OpaqueBrowserFrameViewLayoutTest : public ChromeViewsTestBase {
gfx::Size browser_view_min_size(delegate_->GetBrowserViewMinimumSize()); gfx::Size browser_view_min_size(delegate_->GetBrowserViewMinimumSize());
const int min_width = const int min_width =
browser_view_min_size.width() + tabstrip_min_size.width() + spacing; browser_view_min_size.width() + tabstrip_min_size.width() + spacing;
gfx::Size min_size(layout_manager_->GetMinimumSize(kWindowWidth)); gfx::Size min_size(layout_manager_->GetMinimumSize(root_view_));
EXPECT_EQ(min_width, min_size.width()); EXPECT_EQ(min_width, min_size.width());
int restored_border_height = int restored_border_height =
2 * OpaqueBrowserFrameViewLayout::kFrameBorderThickness + 2 * OpaqueBrowserFrameViewLayout::kFrameBorderThickness +
......
...@@ -14,6 +14,20 @@ LayoutManager::~LayoutManager() { ...@@ -14,6 +14,20 @@ LayoutManager::~LayoutManager() {
void LayoutManager::Installed(View* host) { void LayoutManager::Installed(View* host) {
} }
void LayoutManager::InvalidateLayout() {}
gfx::Size LayoutManager::GetMinimumSize(const View* host) const {
// Fall back to using preferred size if no minimum size calculation is
// available (e.g. legacy layout managers).
//
// Ideally we'd just call GetPreferredSize() on ourselves here, but because
// some legacy views with layout managers override GetPreferredSize(), we need
// to call GetPreferredSize() on the host view instead. The default
// views::View behavior will be to call GetPreferredSize() on this layout
// manager, so the fallback behavior in all other cases is as expected.
return host->GetPreferredSize();
}
int LayoutManager::GetPreferredHeightForWidth(const View* host, int LayoutManager::GetPreferredHeightForWidth(const View* host,
int width) const { int width) const {
return GetPreferredSize(host).height(); return GetPreferredSize(host).height();
......
...@@ -34,16 +34,27 @@ class VIEWS_EXPORT LayoutManager { ...@@ -34,16 +34,27 @@ class VIEWS_EXPORT LayoutManager {
// Notification that this LayoutManager has been installed on |host|. // Notification that this LayoutManager has been installed on |host|.
virtual void Installed(View* host); virtual void Installed(View* host);
// For layout managers that can cache layout data, it's useful to let the
// layout manager know that its current layout might not be valid.
// TODO(dfried): consider if we should include some default behavior (like a
// rolling layout counter).
virtual void InvalidateLayout();
// Called by View::Layout() to position and size the children of |host|. // Called by View::Layout() to position and size the children of |host|.
// Generally this queries |host| for its size and positions and sizes the // Generally this queries |host| for its size and positions and sizes the
// children in a LayoutManager specific way. // children in a LayoutManager specific way.
virtual void Layout(View* host) = 0; virtual void Layout(View* host) = 0;
// Return the preferred size, which is typically the size needed to give each // Returns the preferred size, which is typically the size needed to give each
// child of |host| its preferred size. Generally this is calculated using the // child of |host| its preferred size. Generally this is calculated using the
// View::CalculatePreferredSize() on each of the children of |host|. // View::CalculatePreferredSize() on each of the children of |host|.
virtual gfx::Size GetPreferredSize(const View* host) const = 0; virtual gfx::Size GetPreferredSize(const View* host) const = 0;
// Returns the minimum size, which defaults to the preferred size. Layout
// managers with the ability to collapse or hide child views may override this
// behavior.
virtual gfx::Size GetMinimumSize(const View* host) const;
// Return the preferred height for a particular width. Generally this is // Return the preferred height for a particular width. Generally this is
// calculated using View::GetHeightForWidth() or // calculated using View::GetHeightForWidth() or
// View::CalculatePreferredSize() on each of the children of |host|. Override // View::CalculatePreferredSize() on each of the children of |host|. Override
......
...@@ -423,6 +423,9 @@ void View::SizeToPreferredSize() { ...@@ -423,6 +423,9 @@ void View::SizeToPreferredSize() {
} }
gfx::Size View::GetMinimumSize() const { gfx::Size View::GetMinimumSize() const {
if (layout_manager_)
return layout_manager_->GetMinimumSize(this);
return GetPreferredSize(); return GetPreferredSize();
} }
...@@ -431,7 +434,7 @@ gfx::Size View::GetMaximumSize() const { ...@@ -431,7 +434,7 @@ gfx::Size View::GetMaximumSize() const {
} }
int View::GetHeightForWidth(int w) const { int View::GetHeightForWidth(int w) const {
if (layout_manager_.get()) if (layout_manager_)
return layout_manager_->GetPreferredHeightForWidth(this, w); return layout_manager_->GetPreferredHeightForWidth(this, w);
return GetPreferredSize().height(); return GetPreferredSize().height();
} }
...@@ -586,7 +589,7 @@ void View::Layout() { ...@@ -586,7 +589,7 @@ void View::Layout() {
needs_layout_ = false; needs_layout_ = false;
// If we have a layout manager, let it handle the layout for us. // If we have a layout manager, let it handle the layout for us.
if (layout_manager_.get()) if (layout_manager_)
layout_manager_->Layout(this); layout_manager_->Layout(this);
// Make sure to propagate the Layout() call to any children that haven't // Make sure to propagate the Layout() call to any children that haven't
...@@ -609,6 +612,9 @@ void View::InvalidateLayout() { ...@@ -609,6 +612,9 @@ void View::InvalidateLayout() {
// Always invalidate up. This is needed to handle the case of us already being // Always invalidate up. This is needed to handle the case of us already being
// valid, but not our parent. // valid, but not our parent.
needs_layout_ = true; needs_layout_ = true;
if (layout_manager_)
layout_manager_->InvalidateLayout();
if (parent_) if (parent_)
parent_->InvalidateLayout(); parent_->InvalidateLayout();
} }
...@@ -1496,7 +1502,7 @@ bool View::HasObserver(const ViewObserver* observer) const { ...@@ -1496,7 +1502,7 @@ bool View::HasObserver(const ViewObserver* observer) const {
// Size and disposition -------------------------------------------------------- // Size and disposition --------------------------------------------------------
gfx::Size View::CalculatePreferredSize() const { gfx::Size View::CalculatePreferredSize() const {
if (layout_manager_.get()) if (layout_manager_)
return layout_manager_->GetPreferredSize(this); return layout_manager_->GetPreferredSize(this);
return gfx::Size(); return gfx::Size();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment