summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 20:45:33 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 20:45:33 +0000
commitce2644e0189ee4b8c03f1bc75d6dfff319eaade3 (patch)
treec27c7b644a1f4057ea7d3047a9c5a23b3db3e6c0 /chrome/browser
parentb9437d1e6d77bb0b56c2c408b6e172e1c517a87e (diff)
downloadchromium_src-ce2644e0189ee4b8c03f1bc75d6dfff319eaade3.zip
chromium_src-ce2644e0189ee4b8c03f1bc75d6dfff319eaade3.tar.gz
chromium_src-ce2644e0189ee4b8c03f1bc75d6dfff319eaade3.tar.bz2
Changes tab overview to create a window the max size it can possibly
be so that resize animations are not janktastic. TabOverviewContainer only draws in the parts that are actually used so that it appears as though the window is smaller than it is. This was needed as moving/resizing bounds is way too expensive. BUG=none TEST=none Review URL: http://codereview.chromium.org/132059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18952 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/views/tabs/grid.cc1
-rw-r--r--chrome/browser/views/tabs/tab_overview_container.cc39
-rw-r--r--chrome/browser/views/tabs/tab_overview_container.h10
-rw-r--r--chrome/browser/views/tabs/tab_overview_controller.cc72
-rw-r--r--chrome/browser/views/tabs/tab_overview_controller.h17
5 files changed, 58 insertions, 81 deletions
diff --git a/chrome/browser/views/tabs/grid.cc b/chrome/browser/views/tabs/grid.cc
index 0f3876e..fae3ff7 100644
--- a/chrome/browser/views/tabs/grid.cc
+++ b/chrome/browser/views/tabs/grid.cc
@@ -24,6 +24,7 @@ Grid::Grid()
columns_(0),
rows_(0),
floating_index_(-1) {
+ animation_.SetTweenType(SlideAnimation::EASE_OUT);
}
void Grid::MoveCell(int old_index, int new_index) {
diff --git a/chrome/browser/views/tabs/tab_overview_container.cc b/chrome/browser/views/tabs/tab_overview_container.cc
index 54b6bf2..82402f0 100644
--- a/chrome/browser/views/tabs/tab_overview_container.cc
+++ b/chrome/browser/views/tabs/tab_overview_container.cc
@@ -4,13 +4,9 @@
#include "chrome/browser/views/tabs/tab_overview_container.h"
-#include <gtk/gtk.h>
-
#include "app/gfx/canvas.h"
-#include "app/gfx/path.h"
#include "chrome/browser/views/tabs/tab_overview_grid.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
-#include "views/widget/widget_gtk.h"
// Padding between the edges of us and the grid.
static const int kVerticalPadding = 43;
@@ -19,9 +15,6 @@ static const int kHorizontalPadding = 30;
// Height of the arrow.
static const int kArrowHeight = 28;
-// Inset of the slight rounding on the corners.
-static const int kEdgeInset = 5;
-
TabOverviewContainer::TabOverviewContainer() {
}
@@ -34,33 +27,6 @@ void TabOverviewContainer::SetMaxSize(const gfx::Size& max_size) {
max_size.height() - kVerticalPadding * 2 - kArrowHeight));
}
-void TabOverviewContainer::UpdateWidgetShape(int horizontal_center,
- int width, int height) {
- int bottom_y = height - kArrowHeight;
- int right_edge = width - 1;
- int center = width / 2;
- // The points, in alternating x,y pairs.
- int points[] = {
- kEdgeInset, 0,
- right_edge - kEdgeInset, 0,
- right_edge, kEdgeInset,
- right_edge, bottom_y - kEdgeInset - 1,
- right_edge - kEdgeInset, bottom_y - 1,
- center + kArrowHeight / 2, bottom_y - 1,
- center, bottom_y - 1 + kArrowHeight,
- center - kArrowHeight / 2, bottom_y - 1,
- kEdgeInset, bottom_y - 1,
- 0, bottom_y - 1 - kEdgeInset,
- 0, kEdgeInset,
- };
- gfx::Path path;
- path.moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1]));
- for (size_t i = 2; i < arraysize(points); i += 2)
- path.lineTo(SkIntToScalar(points[i]), SkIntToScalar(points[i + 1]));
-
- GetWidget()->SetShape(path);
-}
-
gfx::Size TabOverviewContainer::GetPreferredSize() {
gfx::Size tab_overview_pref = GetTabOverviewGrid()->GetPreferredSize();
return gfx::Size(kHorizontalPadding * 2 + tab_overview_pref.width(),
@@ -90,11 +56,6 @@ void TabOverviewContainer::Paint(gfx::Canvas* canvas) {
canvas->drawPaint(paint);
}
-void TabOverviewContainer::DidChangeBounds(const gfx::Rect& previous,
- const gfx::Rect& current) {
- Layout();
-}
-
TabOverviewGrid* TabOverviewContainer::GetTabOverviewGrid() {
return static_cast<TabOverviewGrid*>(GetChildViewAt(0));
}
diff --git a/chrome/browser/views/tabs/tab_overview_container.h b/chrome/browser/views/tabs/tab_overview_container.h
index f346192..841fac2 100644
--- a/chrome/browser/views/tabs/tab_overview_container.h
+++ b/chrome/browser/views/tabs/tab_overview_container.h
@@ -10,8 +10,7 @@
class TabOverviewGrid;
// TabOverviewContainer contains TabOverviewGrid. TabOverviewContainer provides
-// padding around the grid as well as maintaining a shape on the containing
-// widget.
+// padding around the grid.
class TabOverviewContainer : public views::View {
public:
TabOverviewContainer();
@@ -21,17 +20,10 @@ class TabOverviewContainer : public views::View {
// adjusting for our borders.
void SetMaxSize(const gfx::Size& max_size);
- // Updates the shape on the containing widget. |horizontal_center| gives the
- // center of the window the parent window we're contained in is centered
- // over.
- void UpdateWidgetShape(int horizontal_center, int width, int height);
-
// View overrides.
virtual gfx::Size GetPreferredSize();
virtual void Layout();
virtual void Paint(gfx::Canvas* canvas);
- virtual void DidChangeBounds(const gfx::Rect& previous,
- const gfx::Rect& current);
private:
TabOverviewGrid* GetTabOverviewGrid();
diff --git a/chrome/browser/views/tabs/tab_overview_controller.cc b/chrome/browser/views/tabs/tab_overview_controller.cc
index 711a2b0..86456c1 100644
--- a/chrome/browser/views/tabs/tab_overview_controller.cc
+++ b/chrome/browser/views/tabs/tab_overview_controller.cc
@@ -12,7 +12,6 @@
#include "chrome/browser/views/tabs/tab_overview_grid.h"
#include "chrome/browser/views/tabs/tab_overview_types.h"
#include "chrome/browser/window_sizer.h"
-#include "views/fill_layout.h"
#include "views/widget/root_view.h"
#include "views/widget/widget_gtk.h"
@@ -40,11 +39,17 @@ TabOverviewController::TabOverviewController(
mutating_grid_(false) {
grid_ = new TabOverviewGrid(this);
+ // Determine the max size for the overview.
+ scoped_ptr<WindowSizer::MonitorInfoProvider> provider(
+ WindowSizer::CreateDefaultMonitorInfoProvider());
+ monitor_bounds_ = provider->GetMonitorWorkAreaMatching(
+ gfx::Rect(monitor_origin.x(), monitor_origin.y(), 1, 1));
+
// Create the host.
views::WidgetGtk* host = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP);
host->set_delete_on_destroy(false);
host->MakeTransparent();
- host->Init(NULL, gfx::Rect(), true);
+ host->Init(NULL, CalculateHostBounds(), true);
TabOverviewTypes::instance()->SetWindowType(
host->GetNativeView(),
TabOverviewTypes::WINDOW_TYPE_CHROME_TAB_SUMMARY,
@@ -53,19 +58,9 @@ TabOverviewController::TabOverviewController(
container_ = new TabOverviewContainer();
container_->AddChildView(grid_);
- host->GetRootView()->SetLayoutManager(new views::FillLayout());
host->GetRootView()->AddChildView(container_);
- // Determine the max size for the overview.
- scoped_ptr<WindowSizer::MonitorInfoProvider> provider(
- WindowSizer::CreateDefaultMonitorInfoProvider());
- monitor_bounds_ = provider->GetMonitorWorkAreaMatching(
- gfx::Rect(monitor_origin.x(), monitor_origin.y(), 1, 1));
- monitor_bounds_.Inset(kMonitorPadding, 0);
- int max_width = monitor_bounds_.width();
- int max_height = static_cast<int>(monitor_bounds_.height() *
- kOverviewHeight);
- container_->SetMaxSize(gfx::Size(max_width, max_height));
+ container_->SetMaxSize(CalculateHostBounds().size());
// TODO: remove this when we get mid point.
horizontal_center_ = monitor_bounds_.x() + monitor_bounds_.width() / 2;
@@ -89,7 +84,11 @@ void TabOverviewController::SetBrowser(Browser* browser,
browser_ = browser;
if (browser_)
model()->AddObserver(this);
- moved_offscreen_ = false;
+ if (moved_offscreen_ && model() && model()->count()) {
+ // Need to reset the bounds if we were offscreen.
+ host_->SetBounds(CalculateHostBounds());
+ moved_offscreen_ = false;
+ }
RecreateCells();
}
@@ -148,7 +147,7 @@ void TabOverviewController::GridAnimationEnded() {
if (moved_offscreen_ || !change_window_bounds_on_animate_ || mutating_grid_)
return;
- SetHostBounds(target_bounds_);
+ container_->SetBounds(target_bounds_);
grid_->UpdateDragController();
change_window_bounds_on_animate_ = false;
}
@@ -159,7 +158,14 @@ void TabOverviewController::GridAnimationProgressed() {
DCHECK(!mutating_grid_);
- SetHostBounds(grid_->AnimationPosition(start_bounds_, target_bounds_));
+ // Schedule a paint before and after changing sizes to deal with the case
+ // of the view shrinking in size.
+ container_->SchedulePaint();
+ container_->SetBounds(
+ grid_->AnimationPosition(start_bounds_, target_bounds_));
+ container_->SchedulePaint();
+
+ // Update the position of the dragged cell.
grid_->UpdateDragController();
}
@@ -242,13 +248,13 @@ void TabOverviewController::RecreateCells() {
if (moved_offscreen_)
return;
- SetHostBounds(CalculateHostBounds());
if (grid()->GetChildViewCount() > 0) {
if (shown_)
host_->Show();
} else {
host_->Hide();
}
+ container_->SetBounds(CalculateContainerBounds());
}
void TabOverviewController::UpdateStartAndTargetBounds() {
@@ -258,24 +264,30 @@ void TabOverviewController::UpdateStartAndTargetBounds() {
if (grid()->GetChildViewCount() == 0) {
host_->Hide();
} else {
- host_->GetBounds(&start_bounds_, true);
- target_bounds_ = CalculateHostBounds();
+ start_bounds_ = container_->bounds();
+ target_bounds_ = CalculateContainerBounds();
change_window_bounds_on_animate_ = (start_bounds_ != target_bounds_);
}
}
-void TabOverviewController::SetHostBounds(const gfx::Rect& bounds) {
- host_->SetBounds(bounds);
- container_->UpdateWidgetShape(horizontal_center_, bounds.width(),
- bounds.height());
+gfx::Rect TabOverviewController::CalculateContainerBounds() {
+ gfx::Rect host_bounds = CalculateHostBounds();
+ const gfx::Size& host_size = CalculateHostBounds().size();
+ gfx::Size pref = container_->GetPreferredSize();
+ int relative_horizontal_center = horizontal_center_ - host_bounds.x();
+ int x = relative_horizontal_center - pref.width() / 2;
+ int y = host_size.height() - pref.height();
+ return gfx::Rect(x, y, pref.width(), pref.height()).
+ AdjustToFit(gfx::Rect(0, 0, host_size.width(), host_size.height()));
}
gfx::Rect TabOverviewController::CalculateHostBounds() {
- gfx::Size pref = container_->GetPreferredSize();
- int x = horizontal_center_ - pref.width() / 2;
- int y = monitor_bounds_.bottom() -
- static_cast<int>(monitor_bounds_.height() * kWindowHeight) -
- kWindowToOverviewPadding - pref.height();
- return gfx::Rect(x, y, pref.width(), pref.height()).
- AdjustToFit(monitor_bounds_);
+ int max_width = monitor_bounds_.width() - kMonitorPadding * 2;
+ int window_height = monitor_bounds_.height() * kWindowHeight;
+ int max_height = static_cast<int>(monitor_bounds_.height() *
+ kOverviewHeight);
+ return gfx::Rect(monitor_bounds_.x() + kMonitorPadding,
+ monitor_bounds_.bottom() - window_height -
+ kWindowToOverviewPadding - max_height, max_width,
+ max_height);
}
diff --git a/chrome/browser/views/tabs/tab_overview_controller.h b/chrome/browser/views/tabs/tab_overview_controller.h
index 50fac90..f977451 100644
--- a/chrome/browser/views/tabs/tab_overview_controller.h
+++ b/chrome/browser/views/tabs/tab_overview_controller.h
@@ -21,6 +21,13 @@ class Widget;
// TabOverviewController is responsible for showing a TabOverviewGrid and
// keeping it in sync with the TabStripModel of a browser.
+//
+// As tabs are added/removed from the TabStripModel the size and position
+// of the container animates. Ideally this would be done by changing the
+// bounds of the host window, but that proved janktastic. Instead the
+// size of the host window is created at the largest possible size the
+// window can be and the bounds of the container are changed during the
+// animation.
class TabOverviewController : public TabStripModelObserver {
public:
// Creates a TabOverviewController that will be shown on the monitor
@@ -85,10 +92,14 @@ class TabOverviewController : public TabStripModelObserver {
// Updates the target and start bounds.
void UpdateStartAndTargetBounds();
- // Sets the bounds of the hosting window to |bounds|.
- void SetHostBounds(const gfx::Rect& bounds);
+ // Returns the bounds for the tab overview container based on the preferred
+ // size of the container. The returned value is the coordinates of the
+ // root view (container's parent).
+ // See comment above class description for more details.
+ gfx::Rect CalculateContainerBounds();
- // Returns the bounds for the window based on the current content.
+ // Returns the bounds needed for the host.
+ // See comment above class description for more details.
gfx::Rect CalculateHostBounds();
// The widget showing the view.