summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-22 16:59:24 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-22 16:59:24 +0000
commitea87eee46258f8a3a75a2d244342b50721e4fb9d (patch)
tree239760d7015a95cad5e8ed2eeb25a55d3fa85bc7 /chrome/browser/views
parentb1d963d60e08720fab32ea5d582e636895feb0d7 (diff)
downloadchromium_src-ea87eee46258f8a3a75a2d244342b50721e4fb9d.zip
chromium_src-ea87eee46258f8a3a75a2d244342b50721e4fb9d.tar.gz
chromium_src-ea87eee46258f8a3a75a2d244342b50721e4fb9d.tar.bz2
Removes tab overview related classes and renames TabOverviewTypes to
WmIpc. BUG=none TEST=none Review URL: http://codereview.chromium.org/646079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/browser_bubble_gtk.cc10
-rw-r--r--chrome/browser/views/extensions/extension_popup.cc11
-rw-r--r--chrome/browser/views/info_bubble.cc10
-rw-r--r--chrome/browser/views/new_browser_window_widget.cc57
-rw-r--r--chrome/browser/views/new_browser_window_widget.h37
-rw-r--r--chrome/browser/views/tabs/grid.cc236
-rw-r--r--chrome/browser/views/tabs/grid.h137
-rw-r--r--chrome/browser/views/tabs/tab_overview_cell.cc96
-rw-r--r--chrome/browser/views/tabs/tab_overview_cell.h58
-rw-r--r--chrome/browser/views/tabs/tab_overview_container.cc111
-rw-r--r--chrome/browser/views/tabs/tab_overview_container.h42
-rw-r--r--chrome/browser/views/tabs/tab_overview_controller.cc365
-rw-r--r--chrome/browser/views/tabs/tab_overview_controller.h190
-rw-r--r--chrome/browser/views/tabs/tab_overview_drag_controller.cc457
-rw-r--r--chrome/browser/views/tabs/tab_overview_drag_controller.h177
-rw-r--r--chrome/browser/views/tabs/tab_overview_grid.cc91
-rw-r--r--chrome/browser/views/tabs/tab_overview_grid.h59
-rw-r--r--chrome/browser/views/tabs/tab_overview_message_listener.cc155
-rw-r--r--chrome/browser/views/tabs/tab_overview_message_listener.h64
-rw-r--r--chrome/browser/views/tabs/tab_overview_types.cc250
-rw-r--r--chrome/browser/views/tabs/tab_overview_types.h286
21 files changed, 20 insertions, 2879 deletions
diff --git a/chrome/browser/views/browser_bubble_gtk.cc b/chrome/browser/views/browser_bubble_gtk.cc
index 66b07c1..cf2ff0c 100644
--- a/chrome/browser/views/browser_bubble_gtk.cc
+++ b/chrome/browser/views/browser_bubble_gtk.cc
@@ -8,7 +8,9 @@
#include "views/widget/widget_gtk.h"
#include "views/window/window.h"
-#include "chrome/browser/views/tabs/tab_overview_types.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/wm_ipc.h"
+#endif
namespace {
@@ -84,10 +86,12 @@ void BrowserBubble::InitPopup() {
pop->SetOpacity(0xFF);
pop->make_transient_to_parent();
pop->Init(frame_->GetNativeView(), bounds_);
- TabOverviewTypes::instance()->SetWindowType(
+#if defined(OS_CHROMEOS)
+ chromeos::WmIpc::instance()->SetWindowType(
pop->GetNativeView(),
- TabOverviewTypes::WINDOW_TYPE_CHROME_INFO_BUBBLE,
+ chromeos::WmIpc::WINDOW_TYPE_CHROME_INFO_BUBBLE,
NULL);
+#endif
pop->SetContentsView(view_);
popup_ = pop;
Reposition();
diff --git a/chrome/browser/views/extensions/extension_popup.cc b/chrome/browser/views/extensions/extension_popup.cc
index 70c9222..c417e8e2 100644
--- a/chrome/browser/views/extensions/extension_popup.cc
+++ b/chrome/browser/views/extensions/extension_popup.cc
@@ -19,10 +19,13 @@
#include "views/window/window.h"
#if defined(OS_LINUX)
-#include "chrome/browser/views/tabs/tab_overview_types.h"
#include "views/widget/widget_gtk.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/wm_ipc.h"
+#endif
+
using views::Widget;
// The minimum/maximum dimensions of the popup.
@@ -80,10 +83,10 @@ ExtensionPopup::ExtensionPopup(ExtensionHost* host,
Widget::DeleteOnDestroy);
#endif
border_widget_->Init(native_window, bounds());
-#if defined(OS_LINUX)
- TabOverviewTypes::instance()->SetWindowType(
+#if defined(OS_CHROMEOS)
+ chromeos::WmIpc::instance()->SetWindowType(
border_widget_->GetNativeView(),
- TabOverviewTypes::WINDOW_TYPE_CHROME_INFO_BUBBLE,
+ chromeos::WmIpc::WINDOW_TYPE_CHROME_INFO_BUBBLE,
NULL);
#endif
diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc
index 9f88fc8..165bc46 100644
--- a/chrome/browser/views/info_bubble.cc
+++ b/chrome/browser/views/info_bubble.cc
@@ -15,8 +15,8 @@
#include "views/widget/root_view.h"
#include "views/window/window.h"
-#if defined(OS_LINUX)
-#include "chrome/browser/views/tabs/tab_overview_types.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/wm_ipc.h"
#endif
// Background color of the bubble.
@@ -240,11 +240,13 @@ void InfoBubble::Init(views::Window* parent,
MakeTransparent();
make_transient_to_parent();
WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), gfx::Rect());
- TabOverviewTypes::instance()->SetWindowType(
+#if defined(OS_CHROMEOS)
+ chromeos::WmIpc::instance()->SetWindowType(
GetNativeView(),
- TabOverviewTypes::WINDOW_TYPE_CHROME_INFO_BUBBLE,
+ chromeos::WmIpc::WINDOW_TYPE_CHROME_INFO_BUBBLE,
NULL);
#endif
+#endif
// Create a View to hold the contents of the main window.
views::View* contents_view = new views::View;
diff --git a/chrome/browser/views/new_browser_window_widget.cc b/chrome/browser/views/new_browser_window_widget.cc
deleted file mode 100644
index 7cc3950..0000000
--- a/chrome/browser/views/new_browser_window_widget.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/new_browser_window_widget.h"
-
-#include "app/resource_bundle.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/views/tabs/tab_overview_types.h"
-#include "chrome/common/page_transition_types.h"
-#include "googleurl/src/gurl.h"
-#include "grit/theme_resources.h"
-#include "views/controls/button/image_button.h"
-#include "views/fill_layout.h"
-#include "views/widget/root_view.h"
-#include "views/widget/widget_gtk.h"
-
-NewBrowserWindowWidget::NewBrowserWindowWidget(Profile* profile)
- : profile_(profile),
- widget_(NULL) {
- views::ImageButton* button = new views::ImageButton(this);
- button->SetImage(views::CustomButton::BS_NORMAL,
- ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_NEW_BROWSER_WINDOW_ICON));
- gfx::Size pref = button->GetPreferredSize();
- views::WidgetGtk* widget =
- new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
- widget->MakeTransparent();
- widget->Init(NULL, gfx::Rect(0, 0, pref.width(), pref.height()));
- TabOverviewTypes::instance()->SetWindowType(
- widget->GetNativeView(),
- TabOverviewTypes::WINDOW_TYPE_CREATE_BROWSER_WINDOW,
- NULL);
- widget->GetRootView()->SetLayoutManager(new views::FillLayout());
- widget->GetRootView()->AddChildView(button);
- widget_ = widget;
- widget->Show();
-}
-
-NewBrowserWindowWidget::~NewBrowserWindowWidget() {
- widget_->Close();
- widget_ = NULL;
-}
-
-void NewBrowserWindowWidget::ButtonPressed(
- views::Button* sender, const views::Event& event) {
- UserMetrics::RecordAction("TabOverview_PressedCreateNewBrowserButton",
- profile_);
-
- Browser* browser = Browser::Create(profile_);
- browser->AddTabWithURL(GURL(), GURL(), PageTransition::START_PAGE,
- true, -1, false, NULL);
- browser->window()->Show();
-}
diff --git a/chrome/browser/views/new_browser_window_widget.h b/chrome/browser/views/new_browser_window_widget.h
deleted file mode 100644
index 5540009..0000000
--- a/chrome/browser/views/new_browser_window_widget.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_NEW_BROWSER_WINDOW_WIDGET_H_
-#define CHROME_BROWSER_VIEWS_NEW_BROWSER_WINDOW_WIDGET_H_
-
-#include "views/controls/button/button.h"
-
-class Profile;
-
-namespace views {
-class Widget;
-}
-
-// NewBrowserWindowWidget creates a window containing a single button that
-// when clicked creates a new Browser. NewBrowserWindowWidget shows the window
-// from its constructor, and closes it from the destructor.
-class NewBrowserWindowWidget : public views::ButtonListener {
- public:
- explicit NewBrowserWindowWidget(Profile* profile);
- ~NewBrowserWindowWidget();
-
- // ButtonListener implementation.
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
-
- private:
- // The profile the browser is created with.
- Profile* profile_;
-
- // The widget containing the button.
- views::Widget* widget_;
-
- DISALLOW_COPY_AND_ASSIGN(NewBrowserWindowWidget);
-};
-
-#endif // CHROME_BROWSER_VIEWS_NEW_BROWSER_WINDOW_WIDGET_H_
diff --git a/chrome/browser/views/tabs/grid.cc b/chrome/browser/views/tabs/grid.cc
deleted file mode 100644
index e6db1e7..0000000
--- a/chrome/browser/views/tabs/grid.cc
+++ /dev/null
@@ -1,236 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/grid.h"
-
-#include "base/compiler_specific.h"
-
-using views::View;
-
-// static
-const int Grid::kCellXPadding = 15;
-// static
-const int Grid::kCellYPadding = 15;
-
-Grid::Grid()
- : ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)),
- modifying_children_(false),
- needs_layout_(false),
- pref_width_(0),
- pref_height_(0),
- cell_width_(0),
- cell_height_(0),
- columns_(0),
- rows_(0),
- floating_index_(-1) {
- animation_.SetTweenType(SlideAnimation::EASE_OUT);
-}
-
-void Grid::MoveCell(int old_index, int new_index) {
- View* cell = GetChildViewAt(old_index);
- modifying_children_ = true;
- RemoveChildView(cell);
- AddChildView(new_index, cell);
- modifying_children_ = false;
-
- CalculateTargetBoundsAndStartAnimation();
-}
-
-void Grid::InsertCell(int index, View* cell) {
- modifying_children_ = true;
- AddChildView(index, cell);
- modifying_children_ = false;
-
- CalculateTargetBoundsAndStartAnimation();
-
- // Set the bounds of the cell to it's target bounds. This way it won't appear
- // to animate.
- if (index != floating_index_) {
- start_bounds_[index] = target_bounds_[index];
- cell->SetBounds(target_bounds_[index]);
- }
-}
-
-void Grid::RemoveCell(int index) {
- modifying_children_ = true;
- RemoveChildView(GetChildViewAt(index));
- modifying_children_ = false;
-
- CalculateTargetBoundsAndStartAnimation();
-}
-
-void Grid::AnimateToTargetBounds() {
- CalculateTargetBoundsAndStartAnimation();
-}
-
-void Grid::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
- if (modifying_children_ || parent != this)
- return;
-
- // Our child views changed without us knowing it. Stop the animation and mark
- // us as dirty (needs_layout_ = true).
- animation_.Stop();
- needs_layout_ = true;
-}
-
-gfx::Rect Grid::CellBounds(int index) {
- int row = index / columns_;
- int col = index % columns_;
- return gfx::Rect(col * cell_width_ + std::max(0, col * kCellXPadding),
- row * cell_height_ + std::max(0, row * kCellYPadding),
- cell_width_, cell_height_);
-}
-
-gfx::Size Grid::GetPreferredSize() {
- if (needs_layout_)
- Layout();
-
- return gfx::Size(pref_width_, pref_height_);
-}
-
-void Grid::Layout() {
- if (!needs_layout_)
- return;
-
- needs_layout_ = false;
- animation_.Stop();
- target_bounds_.clear();
- CalculateCellBounds(&target_bounds_);
- for (size_t i = 0; i < target_bounds_.size(); ++i) {
- if (static_cast<int>(i) != floating_index_)
- GetChildViewAt(i)->SetBounds(target_bounds_[i]);
- }
-}
-
-void Grid::PaintChildren(gfx::Canvas* canvas) {
- int i, c;
- for (i = 0, c = GetChildViewCount(); i < c; ++i) {
- if (i != floating_index_) {
- View* child = GetChildViewAt(i);
- if (!child) {
- NOTREACHED();
- continue;
- }
- child->ProcessPaint(canvas);
- }
- }
-
- // Paint the floating view last. This way it floats on top of all other
- // views.
- if (floating_index_ != -1 && floating_index_ < GetChildViewCount())
- GetChildViewAt(floating_index_)->ProcessPaint(canvas);
-}
-
-void Grid::AnimationEnded(const Animation* animation) {
- SetViewBoundsToTarget();
-}
-
-void Grid::AnimationProgressed(const Animation* animation) {
- DCHECK(GetChildViewCount() == static_cast<int>(target_bounds_.size()));
- for (size_t i = 0; i < target_bounds_.size(); ++i) {
- View* view = GetChildViewAt(i);
- gfx::Rect start_bounds = start_bounds_[i];
- gfx::Rect target_bounds = target_bounds_[i];
- if (static_cast<int>(i) != floating_index_) {
- view->SetBounds(
- animation_.CurrentValueBetween(start_bounds, target_bounds));
- }
- }
- SchedulePaint();
-}
-
-void Grid::AnimationCanceled(const Animation* animation) {
- // Don't do anything when the animation is canceled. Presumably Layout will
- // be invoked, and all children will get set to their appropriate position.
-}
-
-void Grid::CalculateCellBounds(std::vector<gfx::Rect>* bounds) {
- DCHECK(max_size_.width() > 0 && max_size_.height() > 0);
- int cell_count = GetChildViewCount();
- if (cell_count == 0) {
- pref_width_ = pref_height_ = 0;
- return;
- }
-
- gfx::Size cell_pref = GetChildViewAt(0)->GetPreferredSize();
- int col_count, row_count;
- // Assume we get the ideal cell size.
- int cell_width = cell_pref.width();
- int cell_height = cell_pref.height();
- int max_columns = std::max(1, (max_size_.width() + kCellXPadding) /
- (cell_width + kCellXPadding));
- if (cell_count <= max_columns) {
- // All the cells fit in a single row.
- row_count = 1;
- col_count = cell_count;
- } else {
- // Need more than one row to display all.
- int max_rows = std::max(1, (max_size_.height() + kCellYPadding) /
- (cell_height + kCellYPadding));
- col_count = max_columns;
- row_count = cell_count / max_columns;
- if (cell_count % col_count != 0)
- row_count++;
- if (cell_count > max_columns * max_rows) {
- // We don't have enough space for the cells at their ideal size. Keep
- // adding columns (and shrinking down cell sizes) until we fit
- // everything.
- float ratio = static_cast<float>(cell_width) /
- static_cast<float>(cell_height);
- do {
- col_count++;
- cell_width =
- static_cast<float>(max_size_.width() -
- ((col_count - 1) * kCellXPadding)) /
- static_cast<float>(col_count);
- cell_height = static_cast<float>(cell_width) / ratio;
- row_count = std::max(1, (max_size_.height() + kCellYPadding) /
- (cell_height + kCellYPadding));
- } while (row_count * col_count < cell_count);
- row_count = cell_count / col_count;
- if (cell_count % col_count != 0)
- row_count++;
- }
- }
-
- cell_width_ = cell_width;
- cell_height_ = cell_height;
- columns_ = col_count;
- rows_ = row_count;
-
- pref_width_ =
- std::max(0, col_count * (cell_width + kCellXPadding) - kCellXPadding);
- pref_height_ =
- std::max(0, row_count * (cell_height + kCellYPadding) - kCellYPadding);
-
- for (int i = 0; i < cell_count; ++i)
- bounds->push_back(CellBounds(i));
-}
-
-void Grid::CalculateTargetBoundsAndStartAnimation() {
- if (needs_layout_)
- Layout();
-
- // Determine the current bounds.
- start_bounds_.clear();
- start_bounds_.resize(GetChildViewCount());
- for (int i = 0; i < GetChildViewCount(); ++i)
- start_bounds_[i] = GetChildViewAt(i)->bounds();
-
- // Then the target bounds.
- target_bounds_.clear();
- CalculateCellBounds(&target_bounds_);
-
- // And restart the animation.
- animation_.Reset();
- animation_.Show();
-}
-
-void Grid::SetViewBoundsToTarget() {
- DCHECK(GetChildViewCount() == static_cast<int>(target_bounds_.size()));
- for (size_t i = 0; i < target_bounds_.size(); ++i) {
- if (static_cast<int>(i) != floating_index_)
- GetChildViewAt(i)->SetBounds(target_bounds_[i]);
- }
-}
diff --git a/chrome/browser/views/tabs/grid.h b/chrome/browser/views/tabs/grid.h
deleted file mode 100644
index c046737..0000000
--- a/chrome/browser/views/tabs/grid.h
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_GRID_H_
-#define CHROME_BROWSER_VIEWS_TABS_GRID_H_
-
-#include <vector>
-
-#include "app/slide_animation.h"
-#include "base/gfx/rect.h"
-#include "views/view.h"
-
-// Grid is a view that positions its children (cells) in a grid. Grid
-// attempts to layout the children at their preferred size (assuming
-// all cells have the same preferred size) in a single row. If the sum
-// of the widths is greater than the max width, then a new row is
-// added. Once the max number of rows and columns are reached, the
-// cells are shrunk to fit.
-//
-// Grid offers methods to move, insert and remove cells. These end up changing
-// the child views, and animating the transition.
-class Grid : public views::View, public AnimationDelegate {
- public:
- Grid();
-
- // Sets the max size for the Grid. See description above class for details.
- void set_max_size(const gfx::Size& size) { max_size_ = size; }
- const gfx::Size& max_size() const { return max_size_; }
-
- // Moves the child view to the specified index, animating the move.
- void MoveCell(int old_index, int new_index);
-
- // Inserts a cell at the specified index, animating the insertion.
- void InsertCell(int index, views::View* cell);
-
- // Removes the cell at the specified index, animating the removal.
- // WARNING: this does NOT delete the view, it's up to the caller to do that.
- void RemoveCell(int index);
-
- // Calculates the target bounds of each cell and starts the animation timer
- // (assuming it isn't already running). This is invoked for you, but may
- // be invoked to retrigger animation, perhaps after changing the floating
- // index.
- void AnimateToTargetBounds();
-
- // Sets the index of the floating cell. The floating cells bounds are NOT
- // updated along with the rest of the cells, and the floating cell is painted
- // after all other cells. This is typically used during drag and drop when
- // the user is dragging a cell around.
- void set_floating_index(int index) { floating_index_ = index; }
-
- // Returns the number of columns.
- int columns() const { return columns_; }
-
- // Returns the number of rows.
- int rows() const { return rows_; }
-
- // Returns the width of a cell.
- int cell_width() const { return cell_width_; }
-
- // Returns the height of a cell.
- int cell_height() const { return cell_height_; }
-
- // Returns the bounds of the specified cell.
- gfx::Rect CellBounds(int index);
-
- // Returns the animation.
- const SlideAnimation& animation() { return animation_; }
-
- // View overrides.
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child);
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
- void PaintChildren(gfx::Canvas* canvas);
-
- // AnimationDelegate overrides.
- virtual void AnimationEnded(const Animation* animation);
- virtual void AnimationProgressed(const Animation* animation);
- virtual void AnimationCanceled(const Animation* animation);
-
- // Padding between cells.
- static const int kCellXPadding;
- static const int kCellYPadding;
-
- private:
- // Calculates the bounds of each of the cells, adding the result to |bounds|.
- void CalculateCellBounds(std::vector<gfx::Rect>* bounds);
-
- // Resets start_bounds_ to the bounds of the current cells, and invokes
- // CalculateCellBounds to determine the target bounds. Then starts the
- // animation if it isn't already running.
- void CalculateTargetBoundsAndStartAnimation();
-
- // Resets the bounds of each cell to that of target_bounds_.
- void SetViewBoundsToTarget();
-
- // The animation.
- SlideAnimation animation_;
-
- // If true, we're adding/removing a child and can ignore the change in
- // ViewHierarchyChanged.
- bool modifying_children_;
-
- // Do we need a layout? This is set to true any time a child is added/removed.
- bool needs_layout_;
-
- // Max size we layout to.
- gfx::Size max_size_;
-
- // Preferred size.
- int pref_width_;
- int pref_height_;
-
- // Current cell size.
- int cell_width_;
- int cell_height_;
-
- // Number of rows/columns.
- int columns_;
- int rows_;
-
- // See description above setter.
- int floating_index_;
-
- // Used during animation, gives the initial bounds of the views.
- std::vector<gfx::Rect> start_bounds_;
-
- // Used during animation, gives the target bounds of the views.
- std::vector<gfx::Rect> target_bounds_;
-
- DISALLOW_COPY_AND_ASSIGN(Grid);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_GRID_H_
diff --git a/chrome/browser/views/tabs/tab_overview_cell.cc b/chrome/browser/views/tabs/tab_overview_cell.cc
deleted file mode 100644
index 4bebd42..0000000
--- a/chrome/browser/views/tabs/tab_overview_cell.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_cell.h"
-
-#include "app/gfx/favicon_size.h"
-#include "app/gfx/skbitmap_operations.h"
-#include "base/string_util.h"
-#include "views/border.h"
-#include "views/controls/image_view.h"
-#include "views/controls/label.h"
-#include "views/grid_layout.h"
-
-using views::ColumnSet;
-using views::GridLayout;
-
-// Padding between the favicon and label.
-static const int kFavIconPadding = 4;
-
-// Height of the thumbnail.
-static const int kThumbnailHeight = 140;
-static const int kThumbnailWidth = 220;
-
-// Padding between favicon/title and thumbnail.
-static const int kVerticalPadding = 10;
-
-TabOverviewCell::TabOverviewCell() : configured_thumbnail_(false) {
- title_label_ = new views::Label();
- title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
-
- thumbnail_view_ = new views::ImageView();
- thumbnail_view_->SetImageSize(gfx::Size(kThumbnailWidth, kThumbnailHeight));
-
- fav_icon_view_ = new views::ImageView();
- fav_icon_view_->SetImageSize(gfx::Size(kFavIconSize, kFavIconSize));
-
- int title_cs_id = 0;
- int thumbnail_cs_id = 1;
- GridLayout* layout = new GridLayout(this);
- SetLayoutManager(layout);
- ColumnSet* columns = layout->AddColumnSet(title_cs_id);
- columns->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
- GridLayout::USE_PREF, 0, 0);
- columns->AddPaddingColumn(0, kFavIconPadding);
- columns->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
- GridLayout::USE_PREF, 0, 0);
-
- columns = layout->AddColumnSet(thumbnail_cs_id);
- columns->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
- GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, title_cs_id);
- layout->AddView(fav_icon_view_);
- layout->AddView(title_label_);
-
- layout->StartRowWithPadding(1, thumbnail_cs_id, 0, kVerticalPadding);
- layout->AddView(thumbnail_view_);
-
- thumbnail_view_->set_background(
- views::Background::CreateSolidBackground(SK_ColorWHITE));
-
- thumbnail_view_->set_border(
- views::Border::CreateSolidBorder(1, SkColorSetRGB(176, 176, 176)));
-}
-
-void TabOverviewCell::SetThumbnail(const SkBitmap& thumbnail) {
- // Do mipmapped-based resampling to get closer to the correct size. The
- // input bitmap isn't guaranteed to have any specific resolution.
- thumbnail_view_->SetImage(SkBitmapOperations::DownsampleByTwoUntilSize(
- thumbnail, kThumbnailWidth, kThumbnailHeight));
- configured_thumbnail_ = true;
-}
-
-void TabOverviewCell::SetTitle(const string16& title) {
- title_label_->SetText(UTF16ToWide(title));
-}
-
-void TabOverviewCell::SetFavIcon(const SkBitmap& favicon) {
- fav_icon_view_->SetImage(favicon);
-}
-
-bool TabOverviewCell::IsPointInThumbnail(const gfx::Point& point) {
- return thumbnail_view_->bounds().Contains(point);
-}
-
-gfx::Size TabOverviewCell::GetPreferredSize() {
- if (!preferred_size_.IsEmpty())
- return preferred_size_;
-
- // Force the preferred width to that of the thumbnail.
- gfx::Size thumbnail_pref = thumbnail_view_->GetPreferredSize();
- gfx::Size pref = View::GetPreferredSize();
- pref.set_width(thumbnail_pref.width());
- return pref;
-}
diff --git a/chrome/browser/views/tabs/tab_overview_cell.h b/chrome/browser/views/tabs/tab_overview_cell.h
deleted file mode 100644
index 08c0055..0000000
--- a/chrome/browser/views/tabs/tab_overview_cell.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CELL_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CELL_H_
-
-#include "base/string16.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "views/view.h"
-
-namespace views {
-class ImageView;
-class Label;
-}
-
-// A single cell displayed by TabOverviewGrid. TabOverviewCell contains a
-// label, favicon and thumnbail.
-class TabOverviewCell : public views::View {
- public:
- TabOverviewCell();
-
- void SetThumbnail(const SkBitmap& thumbnail);
- void SetTitle(const string16& title);
- void SetFavIcon(const SkBitmap& favicon);
-
- // Sets the preferred size. Normally the preferred size is calculate from
- // the content, but this can be used to fix it at a particular value. Use an
- // empty size to get the default preferred size.
- void set_preferred_size(const gfx::Size& preferred_size) {
- preferred_size_ = preferred_size;
- }
-
- // Returns true if the specified point, in the bounds of the cell, is over
- // the thumbnail.
- bool IsPointInThumbnail(const gfx::Point& point);
-
- // Has the thumbnail been configured? This is true after SetThumbnail
- // is invoked.
- bool configured_thumbnail() const { return configured_thumbnail_; }
-
- // View overrides.
- virtual gfx::Size GetPreferredSize();
-
- private:
- views::Label* title_label_;
- views::ImageView* thumbnail_view_;
- views::ImageView* fav_icon_view_;
-
- // Specific preferred size. See set_preferred_size() for details.
- gfx::Size preferred_size_;
-
- bool configured_thumbnail_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewCell);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CELL_H_
diff --git a/chrome/browser/views/tabs/tab_overview_container.cc b/chrome/browser/views/tabs/tab_overview_container.cc
deleted file mode 100644
index 6843b1e..0000000
--- a/chrome/browser/views/tabs/tab_overview_container.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_container.h"
-
-#include "app/gfx/canvas.h"
-#include "chrome/browser/views/tabs/tab_overview_grid.h"
-#include "third_party/skia/include/core/SkPath.h"
-#include "third_party/skia/include/effects/SkGradientShader.h"
-
-// Padding between the edges of us and the grid.
-static const int kVerticalPadding = 43;
-static const int kHorizontalPadding = 30;
-
-// Height of the arrow.
-static const int kArrowHeight = 28;
-
-// Radius of the corners of the rectangle.
-static const int kEdgeSize = 8;
-
-TabOverviewContainer::TabOverviewContainer() : arrow_center_(0) {
-}
-
-TabOverviewContainer::~TabOverviewContainer() {
-}
-
-void TabOverviewContainer::SetMaxSize(const gfx::Size& max_size) {
- GetTabOverviewGrid()->set_max_size(
- gfx::Size(max_size.width() - kHorizontalPadding * 2,
- max_size.height() - kVerticalPadding * 2 - kArrowHeight));
-}
-
-gfx::Size TabOverviewContainer::GetPreferredSize() {
- gfx::Size tab_overview_pref = GetTabOverviewGrid()->GetPreferredSize();
- return gfx::Size(kHorizontalPadding * 2 + tab_overview_pref.width(),
- kVerticalPadding * 2 + tab_overview_pref.height() +
- kArrowHeight);
-}
-
-void TabOverviewContainer::Layout() {
- GetTabOverviewGrid()->SetBounds(kHorizontalPadding, kVerticalPadding,
- width() - kHorizontalPadding * 2,
- height() - kVerticalPadding * 2 -
- kArrowHeight);
-}
-
-void TabOverviewContainer::Paint(gfx::Canvas* canvas) {
- // Create a path with a rounded rect and arrow pointing down.
- SkPath outline;
- int right = width() - 1;
- int bottom = height() - 1 - kArrowHeight;
- outline.moveTo(SkIntToScalar(kEdgeSize), SkIntToScalar(0));
- outline.arcTo(SkIntToScalar(right), SkIntToScalar(0),
- SkIntToScalar(right), SkIntToScalar(bottom),
- SkIntToScalar(kEdgeSize));
- outline.arcTo(SkIntToScalar(right), SkIntToScalar(bottom),
- SkIntToScalar(0), SkIntToScalar(bottom),
- SkIntToScalar(kEdgeSize));
- // Convert arrow_center to our coordinates.
- int arrow_center = arrow_center_ - bounds().x();
- if (arrow_center >= kArrowHeight && arrow_center < width() - kArrowHeight) {
- // Only draw the arrow if we have enough space.
- outline.lineTo(SkIntToScalar(arrow_center + kArrowHeight / 2),
- SkIntToScalar(bottom));
- outline.lineTo(SkIntToScalar(arrow_center),
- SkIntToScalar(bottom + kArrowHeight));
- outline.lineTo(SkIntToScalar(arrow_center - kArrowHeight / 2),
- SkIntToScalar(bottom));
- }
- outline.arcTo(SkIntToScalar(0), SkIntToScalar(bottom),
- SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(kEdgeSize));
- outline.arcTo(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(right), SkIntToScalar(0),
- SkIntToScalar(kEdgeSize));
-
- canvas->save();
- // Clip out the outline.
- canvas->clipPath(outline);
-
- // Fill the interior with a gradient.
- SkPoint points[] = { { SkIntToScalar(0), SkIntToScalar(0) },
- { SkIntToScalar(0), SkIntToScalar(height()) } };
- SkColor colors[] = { SkColorSetARGB(242, 255, 255, 255),
- SkColorSetARGB(212, 255, 255, 255), };
- SkShader* shader = SkGradientShader::CreateLinear(
- points, colors, NULL, 2, SkShader::kRepeat_TileMode);
- SkPaint paint;
- paint.setShader(shader);
- shader = NULL;
- paint.setStyle(SkPaint::kFill_Style);
- paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
- canvas->drawPaint(paint);
-
- // Restore the canvas (resetting the clip).
- canvas->restore();
-
- SkPaint paint2;
- paint2.setStyle(SkPaint::kStroke_Style);
- paint2.setAntiAlias(true);
- paint2.setColor(SK_ColorWHITE);
- paint2.setStrokeWidth(SkIntToScalar(0));
-
- // And stroke the rounded rect with arrow pointing down.
- canvas->drawPath(outline, paint2);
-}
-
-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
deleted file mode 100644
index fdc63e0..0000000
--- a/chrome/browser/views/tabs/tab_overview_container.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CONTAINER_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CONTAINER_H_
-
-#include "views/view.h"
-
-class TabOverviewGrid;
-
-// TabOverviewContainer contains TabOverviewGrid. TabOverviewContainer provides
-// padding around the grid.
-class TabOverviewContainer : public views::View {
- public:
- TabOverviewContainer();
- virtual ~TabOverviewContainer();
-
- // Sets the max size. This ends up being passed down to the grid after
- // adjusting for our borders.
- void SetMaxSize(const gfx::Size& max_size);
-
- // View overrides.
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
- virtual void Paint(gfx::Canvas* canvas);
-
- // Sets the location of the arrow, along the x-axis.
- //
- // WARNING: this is the coordinate system of the parent, NOT this view.
- void set_arrow_center(int x) { arrow_center_ = x; }
-
- private:
- TabOverviewGrid* GetTabOverviewGrid();
-
- // See set_arrow_center for details.
- int arrow_center_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewContainer);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CONTAINER_H_
diff --git a/chrome/browser/views/tabs/tab_overview_controller.cc b/chrome/browser/views/tabs/tab_overview_controller.cc
deleted file mode 100644
index f9c4d1f2..0000000
--- a/chrome/browser/views/tabs/tab_overview_controller.cc
+++ /dev/null
@@ -1,365 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_controller.h"
-
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/thumbnail_generator.h"
-#include "chrome/browser/views/frame/browser_extender.h"
-#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/tabs/tab_overview_cell.h"
-#include "chrome/browser/views/tabs/tab_overview_container.h"
-#include "chrome/browser/views/tabs/tab_overview_drag_controller.h"
-#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 "chrome/common/x11_util.h"
-#include "views/widget/root_view.h"
-#include "views/widget/widget_gtk.h"
-#include "views/window/window.h"
-
-// Horizontal padding from the edge of the monitor to the overview.
-static int kMonitorPadding = 20;
-// Vertical padding between the overview and the windows along on the bottom.
-static int kWindowToOverviewPadding = 25;
-// Height of the windows along the bottom, as a percentage of the monitors
-// height.
-static float kWindowHeight = .30;
-// Height of the tab overview, as a percentage of monitors height.
-static float kOverviewHeight = .55;
-
-TabOverviewController::TabOverviewController(
- const gfx::Point& monitor_origin)
- : host_(NULL),
- container_(NULL),
- grid_(NULL),
- browser_(NULL),
- drag_browser_(NULL),
- moved_offscreen_(false),
- shown_(false),
- horizontal_center_(0),
- change_window_bounds_on_animate_(false),
- mutating_grid_(false),
- show_thumbnails_(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, CalculateHostBounds());
- TabOverviewTypes::instance()->SetWindowType(
- host->GetNativeView(),
- TabOverviewTypes::WINDOW_TYPE_CHROME_TAB_SUMMARY,
- NULL);
- host_ = host;
-
- container_ = new TabOverviewContainer();
- container_->AddChildView(grid_);
- host->GetRootView()->AddChildView(container_);
-
- container_->SetMaxSize(CalculateHostBounds().size());
-
- horizontal_center_ = monitor_bounds_.x() + monitor_bounds_.width() / 2;
-}
-
-TabOverviewController::~TabOverviewController() {
- if (browser_)
- model()->RemoveObserver(this);
- host_->Close();
- // The drag controller may call back to us from it's destructor. Make sure
- // it's destroyed before us.
- grid()->CancelDrag();
-}
-
-void TabOverviewController::SetBrowser(Browser* browser,
- int horizontal_center) {
- horizontal_center_ = horizontal_center;
- if (browser_)
- model()->RemoveObserver(this);
- browser_ = browser;
- if (browser_)
- model()->AddObserver(this);
-
- show_thumbnails_ = false;
- StartDelayTimer();
-
- gfx::Rect host_bounds = CalculateHostBounds();
- if (moved_offscreen_ && model() && model()->count()) {
- // Need to reset the bounds if we were offscreen.
- host_->SetBounds(host_bounds);
- moved_offscreen_ = false;
- } else if (!model() && shown_) {
- MoveOffscreen();
- }
- if (!moved_offscreen_)
- container_->SchedulePaint();
-
- RecreateCells();
-
- container_->set_arrow_center(horizontal_center_ - host_bounds.x());
-
- if (!moved_offscreen_)
- container_->SchedulePaint();
-}
-
-TabStripModel* TabOverviewController::model() const {
- return browser_ ? browser_->tabstrip_model() : NULL;
-}
-
-void TabOverviewController::SetMouseOverMiniWindow(bool over_mini_window) {
- if (grid_->drag_controller())
- grid_->drag_controller()->set_mouse_over_mini_window(over_mini_window);
-}
-
-void TabOverviewController::Show() {
- if (host_->IsVisible())
- return;
-
- shown_ = true;
- DCHECK(model()); // The model needs to be set before showing.
- host_->Show();
-
- show_thumbnails_ = false;
- StartDelayTimer();
-}
-
-void TabOverviewController::ConfigureCell(TabOverviewCell* cell,
- TabContents* contents) {
- if (contents) {
- cell->SetTitle(contents->GetTitle());
- cell->SetFavIcon(contents->GetFavIcon());
-
- if (show_thumbnails_) {
- ThumbnailGenerator* generator =
- g_browser_process->GetThumbnailGenerator();
- cell->SetThumbnail(
- generator->GetThumbnailForRenderer(contents->render_view_host()));
- }
- cell->SchedulePaint();
- } else {
- // Need to figure out under what circumstances this is null and deal.
- NOTIMPLEMENTED();
-
- // Make sure we set the thumbnail, otherwise configured_thumbnail
- // remains false and ConfigureNextUnconfiguredCell would get stuck.
- if (show_thumbnails_)
- cell->SetThumbnail(SkBitmap());
- }
-}
-
-void TabOverviewController::DragStarted() {
- DCHECK(!drag_browser_);
- drag_browser_ = browser_;
- static_cast<BrowserView*>(drag_browser_->window())->
- browser_extender()->set_can_close(false);
-}
-
-void TabOverviewController::DragEnded() {
- static_cast<BrowserView*>(drag_browser_->window())->
- browser_extender()->set_can_close(true);
- if (drag_browser_->tabstrip_model()->count() == 0)
- drag_browser_->tabstrip_model()->delegate()->CloseFrameAfterDragSession();
- drag_browser_ = NULL;
-}
-
-void TabOverviewController::MoveOffscreen() {
- gfx::Rect bounds;
- moved_offscreen_ = true;
- host_->GetBounds(&bounds, true);
- host_->SetBounds(gfx::Rect(-10000, -10000, bounds.width(), bounds.height()));
-}
-
-void TabOverviewController::SelectTab(int index) {
- browser_->SelectTabContentsAt(index, true);
-}
-
-void TabOverviewController::FocusBrowser() {
- static_cast<BrowserView*>(browser_->window())->GetWindow()->Activate();
-}
-
-void TabOverviewController::GridAnimationEnded() {
- if (moved_offscreen_ || !change_window_bounds_on_animate_ || mutating_grid_)
- return;
-
- container_->SetBounds(target_bounds_);
- grid_->UpdateDragController();
- change_window_bounds_on_animate_ = false;
-}
-
-void TabOverviewController::GridAnimationProgressed() {
- if (moved_offscreen_ || !change_window_bounds_on_animate_)
- return;
-
- DCHECK(!mutating_grid_);
-
- // Schedule a paint before and after changing sizes to deal with the case
- // of the view shrinking in size.
- container_->SchedulePaint();
- container_->SetBounds(
- grid_->animation().CurrentValueBetween(start_bounds_, target_bounds_));
- container_->SchedulePaint();
-
- // Update the position of the dragged cell.
- grid_->UpdateDragController();
-}
-
-void TabOverviewController::GridAnimationCanceled() {
- change_window_bounds_on_animate_ = false;
-}
-
-void TabOverviewController::TabInsertedAt(TabContents* contents,
- int index,
- bool foreground) {
- if (!grid_->modifying_model())
- grid_->CancelDrag();
-
- TabOverviewCell* child = new TabOverviewCell();
- ConfigureCell(child, index);
- mutating_grid_ = true;
- grid_->InsertCell(index, child);
- mutating_grid_ = false;
-
- UpdateStartAndTargetBounds();
-}
-
-void TabOverviewController::TabClosingAt(TabContents* contents, int index) {
- // Nothing to do, we only care when the tab is actually detached.
-}
-
-void TabOverviewController::TabDetachedAt(TabContents* contents, int index) {
- if (!grid_->modifying_model())
- grid_->CancelDrag();
-
- scoped_ptr<TabOverviewCell> child(grid_->GetTabOverviewCellAt(index));
- mutating_grid_ = true;
- grid_->RemoveCell(index);
- mutating_grid_ = false;
-
- UpdateStartAndTargetBounds();
-}
-
-void TabOverviewController::TabMoved(TabContents* contents,
- int from_index,
- int to_index) {
- if (!grid_->modifying_model())
- grid_->CancelDrag();
-
- mutating_grid_ = true;
- grid_->MoveCell(from_index, to_index);
- mutating_grid_ = false;
-
- UpdateStartAndTargetBounds();
-}
-
-void TabOverviewController::TabChangedAt(TabContents* contents, int index,
- TabChangeType change_type) {
- ConfigureCell(grid_->GetTabOverviewCellAt(index), index);
-}
-
-void TabOverviewController::TabStripEmpty() {
- if (!grid_->modifying_model()) {
- grid_->CancelDrag();
- // The tab strip is empty, hide the grid.
- host_->Hide();
- }
-}
-
-void TabOverviewController::ConfigureCell(TabOverviewCell* cell, int index) {
- ConfigureCell(cell, model()->GetTabContentsAt(index));
-}
-
-void TabOverviewController::RecreateCells() {
- grid_->RemoveAllChildViews(true);
-
- if (model()) {
- for (int i = 0; i < model()->count(); ++i) {
- TabOverviewCell* child = new TabOverviewCell();
- ConfigureCell(child, i);
- grid_->AddChildView(child);
- }
- }
-
- if (moved_offscreen_)
- return;
-
- if (grid()->GetChildViewCount() > 0) {
- if (shown_)
- host_->Show();
- } else {
- host_->Hide();
- }
- container_->SetBounds(CalculateContainerBounds());
-}
-
-void TabOverviewController::UpdateStartAndTargetBounds() {
- if (moved_offscreen_ || !shown_)
- return;
-
- if (grid()->GetChildViewCount() == 0) {
- host_->Hide();
- } else {
- start_bounds_ = container_->bounds();
- target_bounds_ = CalculateContainerBounds();
- change_window_bounds_on_animate_ = (start_bounds_ != target_bounds_);
- }
-}
-
-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() {
- 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);
-}
-
-void TabOverviewController::StartConfiguring() {
- show_thumbnails_ = true;
- configure_timer_.Stop();
- configure_timer_.Start(
- base::TimeDelta::FromMilliseconds(10), this,
- &TabOverviewController::ConfigureNextUnconfiguredCell);
-}
-
-void TabOverviewController::ConfigureNextUnconfiguredCell() {
- for (int i = 0; i < grid_->GetChildViewCount(); ++i) {
- TabOverviewCell* cell = grid_->GetTabOverviewCellAt(i);
- if (!cell->configured_thumbnail()) {
- ConfigureCell(cell, i);
- return;
- }
- }
- configure_timer_.Stop();
-}
-
-void TabOverviewController::StartDelayTimer() {
- configure_timer_.Stop();
- delay_timer_.Stop();
- delay_timer_.Start(
- base::TimeDelta::FromMilliseconds(350), this,
- &TabOverviewController::StartConfiguring);
-}
diff --git a/chrome/browser/views/tabs/tab_overview_controller.h b/chrome/browser/views/tabs/tab_overview_controller.h
deleted file mode 100644
index 3110f7d..0000000
--- a/chrome/browser/views/tabs/tab_overview_controller.h
+++ /dev/null
@@ -1,190 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CONTROLLER_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CONTROLLER_H_
-
-#include "base/gfx/rect.h"
-#include "base/scoped_ptr.h"
-#include "base/timer.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
-
-class Animation;
-class Browser;
-class TabOverviewCell;
-class TabOverviewContainer;
-class TabOverviewGrid;
-
-namespace views {
-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.
-//
-// As obtaining and setting thumbnails is expensive we delay setting the
-// thumbnail. The delay is controlled by delay_timer_. Once the timer fires
-// another timer is started (configure_timer_). This timer invokes
-// ConfigureNextUnconfiguredCell, which obtains and sets the thumbnail of
-// the next uncofigured cell. ConfigureNextUnconfiguredCell only configures
-// one cell at a time.
-class TabOverviewController : public TabStripModelObserver {
- public:
- // Creates a TabOverviewController that will be shown on the monitor
- // containing |monitor_origin|.
- explicit TabOverviewController(const gfx::Point& monitor_origin);
- ~TabOverviewController();
-
- // Sets the browser we're showing the tab strip for. |horizontal_center|
- // gives the center of the window.
- void SetBrowser(Browser* browser, int horizontal_center);
- Browser* browser() const { return browser_; }
- TabOverviewGrid* grid() const { return grid_; }
- TabStripModel* model() const;
-
- // Returns true if the grid has been moved off screen. The grid is moved
- // offscren if the user detaches the last tab in the tab strip.
- bool moved_offscreen() const { return moved_offscreen_; }
-
- // Sets whether the mouse is over a mini-window.
- void SetMouseOverMiniWindow(bool over_mini_window);
-
- // Shows the grid.
- void Show();
-
- // Configures a cell from the model.
- void ConfigureCell(TabOverviewCell* cell, TabContents* contents);
-
- // Invoked from TabOverviewDragController.
- void DragStarted();
- void DragEnded();
- void MoveOffscreen();
-
- // Selects the TabContents at |index|. This is invoked from the
- // TabOverviewDragController when the user mouses down on a cell.
- void SelectTab(int index);
-
- // Focuses the current browser. This is invoked from the
- // TabOverviewDragController if the user releases the mouse over a cell
- // without dragging.
- void FocusBrowser();
-
- // Forwarded from TabOverviewGrid as the animation of the grid changes.
- void GridAnimationEnded();
- void GridAnimationProgressed();
- void GridAnimationCanceled();
-
- // TabStripModelObserver overrides.
- virtual void TabInsertedAt(TabContents* contents,
- int index,
- bool foreground);
- virtual void TabClosingAt(TabContents* contents, int index);
- virtual void TabDetachedAt(TabContents* contents, int index);
- virtual void TabMoved(TabContents* contents,
- int from_index,
- int to_index);
- virtual void TabChangedAt(TabContents* contents, int index,
- TabChangeType change_type);
- virtual void TabStripEmpty();
- // Currently don't care about these as we're not rendering the selection.
- virtual void TabDeselectedAt(TabContents* contents, int index) { }
- virtual void TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
- int index,
- bool user_gesture) { }
-
- private:
- // Configures a cell from the model.
- void ConfigureCell(TabOverviewCell* cell, int index);
-
- // Removes all the cells in the grid and populates it from the model.
- void RecreateCells();
-
- // Updates the target and start bounds.
- void UpdateStartAndTargetBounds();
-
- // 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 needed for the host.
- // See comment above class description for more details.
- gfx::Rect CalculateHostBounds();
-
- // Invoked by delay_timer_. Sets show_thumbnails_ to true and starts
- // configure_timer_.
- void StartConfiguring();
-
- // Finds the first cell with no thumbnail and invokes ConfigureCell for
- // it. If all the thumnbails have been set configure_timer_ is stopped.
- void ConfigureNextUnconfiguredCell();
-
- // Starts the delay timer.
- void StartDelayTimer();
-
- // The widget showing the view.
- views::Widget* host_;
-
- // Bounds of the monitor we're being displayed on. This is used to position
- // the widget.
- gfx::Rect monitor_bounds_;
-
- // View containing the grid, owned by host.
- TabOverviewContainer* container_;
-
- // The view. This is owned by host.
- TabOverviewGrid* grid_;
-
- // The browser, not owned by us.
- Browser* browser_;
-
- // The browser a drag was started on.
- Browser* drag_browser_;
-
- // True if the host has been moved offscreen.
- bool moved_offscreen_;
-
- // Has Show been invoked?
- bool shown_;
-
- // Position of the center of the window along the horizontal axis. This is
- // used to position the overview window.
- int horizontal_center_;
-
- // Should we change the window bounds on animate? This is true while the
- // animation is running on the grid to move things around.
- bool change_window_bounds_on_animate_;
-
- // When the model changes we animate the bounds of the window. These two
- // give the start and target bounds of the window.
- gfx::Rect start_bounds_;
- gfx::Rect target_bounds_;
-
- // Are we in the process of mutating the grid? This is used to avoid changing
- // bounds when we're responsible for the mutation.
- bool mutating_grid_;
-
- // Should we set the thumbnails? This is initially false, then set to true
- // by StartConfiguring.
- bool show_thumbnails_;
-
- // See description above class for details.
- base::OneShotTimer<TabOverviewController> delay_timer_;
-
- // See description above class for details.
- base::RepeatingTimer<TabOverviewController> configure_timer_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewController);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_CONTROLLER_H_
diff --git a/chrome/browser/views/tabs/tab_overview_drag_controller.cc b/chrome/browser/views/tabs/tab_overview_drag_controller.cc
deleted file mode 100644
index b609489..0000000
--- a/chrome/browser/views/tabs/tab_overview_drag_controller.cc
+++ /dev/null
@@ -1,457 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_drag_controller.h"
-
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/dock_info.h"
-#include "chrome/browser/gtk/browser_window_gtk.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tabs/tab_strip_model.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/views/tabs/tab_overview_cell.h"
-#include "chrome/browser/views/tabs/tab_overview_controller.h"
-#include "chrome/browser/views/tabs/tab_overview_grid.h"
-#include "chrome/browser/views/tabs/tab_overview_types.h"
-#include "chrome/common/notification_service.h"
-#include "views/fill_layout.h"
-#include "views/view.h"
-#include "views/widget/root_view.h"
-#include "views/widget/widget_gtk.h"
-
-TabOverviewDragController::TabOverviewDragController(
- TabOverviewController* controller)
- : controller_(controller),
- original_model_(controller->model()),
- current_index_(-1),
- original_index_(-1),
- detached_tab_(NULL),
- original_delegate_(NULL),
- x_offset_(0),
- y_offset_(0),
- dragging_(false),
- modifying_model_(false),
- detached_window_(NULL),
- hidden_browser_(NULL),
- mouse_over_mini_window_(false) {
-}
-
-TabOverviewDragController::~TabOverviewDragController() {
- if (dragging_)
- controller_->DragEnded();
- if (original_index_ != -1)
- RevertDrag(false);
-}
-
-bool TabOverviewDragController::Configure(const gfx::Point& location) {
- // Find the cell the user clicked on.
- TabOverviewCell* cell = NULL;
- int index = -1;
- for (int i = 0; i < grid()->GetChildViewCount(); ++i) {
- views::View* child = grid()->GetChildViewAt(i);
- if (child->bounds().Contains(location)) {
- index = i;
- cell = static_cast<TabOverviewCell*>(child);
- break;
- }
- }
- if (!cell)
- return false; // User didn't click on a cell.
-
- // Only start a drag if the user clicks on the thumbnail.
- gfx::Point cell_point(location);
- grid()->ConvertPointToView(grid(), cell, &cell_point);
- if (!cell->IsPointInThumbnail(cell_point))
- return false;
-
- current_index_ = original_index_ = index;
- origin_ = location;
- x_offset_ = location.x() - cell->bounds().x();
- y_offset_ = location.y() - cell->bounds().y();
-
- // Ask the controller to select the cell.
- controller_->SelectTab(index);
-
- if (controller_->browser()) {
- browser_window_size_ =
- controller_->browser()->window()->GetRestoredBounds().size();
- }
-
- return true;
-}
-
-void TabOverviewDragController::Drag(const gfx::Point& location) {
- if (original_index_ == -1)
- return;
-
- if (!dragging_ &&
- views::View::ExceededDragThreshold(location.x() - origin_.x(),
- location.y() - origin_.y())) {
- // Start dragging.
- dragging_ = true;
- controller_->DragStarted();
- grid()->set_floating_index(current_index_);
- UserMetrics::RecordAction("TabOverview_DragCell",
- original_model_->profile());
- }
- if (dragging_)
- DragCell(location);
-}
-
-void TabOverviewDragController::CommitDrag(const gfx::Point& location) {
- if (original_index_ == -1)
- return;
-
- Drag(location);
- if (detached_tab_) {
- if (mouse_over_mini_window_) {
- // Dragged over a mini window, add as the last tab to the browser.
- Attach(model()->count());
- UserMetrics::RecordAction("TabOverview_DropOnMiniWindow",
- original_model_->profile());
- } else {
- DropTab(location);
- }
- } else if (!dragging_) {
- // We haven't started dragging. Tell the controller to focus the browser.
- controller_->FocusBrowser();
- } else {
- // The tab is already in position, nothing to do but animate the change.
- grid()->set_floating_index(-1);
- grid()->AnimateToTargetBounds();
- }
-
- // Set the index to -1 so we know not to do any cleanup.
- original_index_ = -1;
-}
-
-void TabOverviewDragController::RevertDrag(bool tab_destroyed) {
- if (original_index_ == -1)
- return;
-
- modifying_model_ = true;
- if (detached_tab_) {
- // Tab is currently detached, add it back to the original tab strip.
- if (!tab_destroyed) {
- original_model_->InsertTabContentsAt(original_index_,
- detached_tab_, true, false);
- }
- SetDetachedContents(NULL);
- detached_window_->Close();
- detached_window_ = NULL;
-
- if (hidden_browser_) {
- gtk_widget_show(GTK_WIDGET(static_cast<BrowserWindowGtk*>(
- hidden_browser_->window())->GetNativeHandle()));
- }
- } else if (original_model_ != model() && !tab_destroyed) {
- // The tab was added to a different tab strip. Move it back to the
- // original.
- TabContents* contents = model()->DetachTabContentsAt(current_index_);
- original_model_->InsertTabContentsAt(original_index_, contents, true,
- false);
- } else if (current_index_ != original_index_ && !tab_destroyed) {
- original_model_->MoveTabContentsAt(current_index_, original_index_, true);
- }
- modifying_model_ = false;
-
- // Set the index to -1 so we know not to do any cleanup.
- original_index_ = -1;
-}
-
-TabOverviewGrid* TabOverviewDragController::grid() const {
- return controller_->grid();
-}
-
-TabStripModel* TabOverviewDragController::model() const {
- return controller_->model();
-}
-
-void TabOverviewDragController::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
- DCHECK(Source<TabContents>(source).ptr() == detached_tab_);
- RevertDrag(true);
-}
-
-void TabOverviewDragController::OpenURLFromTab(
- TabContents* source,
- const GURL& url,
- const GURL& referrer,
- WindowOpenDisposition disposition,
- PageTransition::Type transition) {
- if (original_delegate_) {
- if (disposition == CURRENT_TAB)
- disposition = NEW_WINDOW;
-
- original_delegate_->OpenURLFromTab(source, url, referrer,
- disposition, transition);
- }
-}
-
-void TabOverviewDragController::NavigationStateChanged(
- const TabContents* source,
- unsigned changed_flags) {
-}
-
-void TabOverviewDragController::AddNewContents(
- TabContents* source,
- TabContents* new_contents,
- WindowOpenDisposition disposition,
- const gfx::Rect& initial_pos,
- bool user_gesture) {
- DCHECK(disposition != CURRENT_TAB);
-
- // Theoretically could be called while dragging if the page tries to
- // spawn a window. Route this message back to the browser in most cases.
- if (original_delegate_) {
- original_delegate_->AddNewContents(source, new_contents, disposition,
- initial_pos, user_gesture);
- }
-}
-
-void TabOverviewDragController::ActivateContents(TabContents* contents) {
- // Ignored.
-}
-
-void TabOverviewDragController::LoadingStateChanged(TabContents* source) {
-}
-
-void TabOverviewDragController::CloseContents(TabContents* source) {
- // Theoretically could be called by a window. Should be ignored
- // because window.close() is ignored (usually, even though this
- // method gets called.)
-}
-
-void TabOverviewDragController::MoveContents(TabContents* source,
- const gfx::Rect& pos) {
- // Theoretically could be called by a web page trying to move its
- // own window. Should be ignored since we're moving the window...
-}
-
-bool TabOverviewDragController::IsPopup(TabContents* source) {
- return false;
-}
-
-void TabOverviewDragController::ToolbarSizeChanged(TabContents* source,
- bool finished) {
- // Dragged tabs don't care about this.
-}
-
-void TabOverviewDragController::URLStarredChanged(TabContents* source,
- bool starred) {
- // Ignored.
-}
-
-void TabOverviewDragController::UpdateTargetURL(TabContents* source,
- const GURL& url) {
- // Ignored.
-}
-
-void TabOverviewDragController::DragCell(const gfx::Point& location) {
- if (controller_->moved_offscreen()) {
- MoveDetachedWindow(location);
- return;
- }
-
- int col = (location.x() - x_offset_ + grid()->cell_width() / 2) /
- (grid()->cell_width() + TabOverviewGrid::kCellXPadding);
- int row = (location.y() - y_offset_ + grid()->cell_height() / 2) /
- (grid()->cell_height() + TabOverviewGrid::kCellYPadding);
- gfx::Rect local_bounds = grid()->GetLocalBounds(true);
- if (!local_bounds.Contains(location)) {
- // Local bounds doesn't contain the point, allow dragging to the left/right
- // of us.
- views::View* root = grid()->GetParent();
- gfx::Rect allowed_bounds = local_bounds;
- gfx::Point root_offset;
- views::View::ConvertPointToView(grid(), root, &root_offset);
- allowed_bounds.Offset(-root_offset.x(), 0);
- allowed_bounds.set_width(root->width());
- if (!allowed_bounds.Contains(location)) {
- // The user dragged outside the grid.
- if (detached_tab_) {
- // We've already created the detached window, move it.
- MoveDetachedWindow(location);
- } else {
- // Detach the cell.
- Detach(location);
- }
- return;
- }
- if (location.x() < 0) {
- col = 0;
- } else if (location.x() >= grid()->width()) {
- col = grid()->columns();
- } else {
- col = (location.x() + grid()->cell_width() / 2) /
- (grid()->cell_width() + TabOverviewGrid::kCellXPadding);
- }
- }
- int new_index = std::min(model()->count() - 1,
- row * grid()->columns() + col);
- if (detached_tab_) {
- // The user dragged a detached tab back over the grid, reattach it.
- Attach(new_index);
- } else if (new_index != current_index_) {
- grid()->set_floating_index(new_index);
- modifying_model_ = true;
- model()->MoveTabContentsAt(current_index_, new_index, false);
- modifying_model_ = false;
- current_index_ = new_index;
- }
- gfx::Rect target_bounds = grid()->CellBounds(current_index_);
- target_bounds.Offset(location.x() - target_bounds.x() - x_offset_,
- location.y() - target_bounds.y() - y_offset_);
- target_bounds.set_y(row * (grid()->cell_height() +
- TabOverviewGrid::kCellYPadding));
- target_bounds = target_bounds.AdjustToFit(grid()->GetLocalBounds(true));
- views::View* cell = grid()->GetChildViewAt(new_index);
- gfx::Rect cell_bounds = cell->bounds();
- if (target_bounds.origin() != cell_bounds.origin()) {
- grid()->SchedulePaint(cell_bounds, false);
- grid()->SchedulePaint(target_bounds, false);
- cell->SetBounds(target_bounds);
- }
-}
-
-void TabOverviewDragController::Attach(int index) {
- DCHECK(detached_tab_);
- DCHECK(model());
- current_index_ = index;
- modifying_model_ = true;
- model()->InsertTabContentsAt(index, detached_tab_, true, false);
- modifying_model_ = false;
- grid()->set_floating_index(index);
- SetDetachedContents(NULL);
-
- detached_window_->Close();
- detached_window_ = NULL;
-}
-
-void TabOverviewDragController::Detach(const gfx::Point& location) {
- if (detached_tab_) {
- // Already detached.
- return;
- }
-
- UserMetrics::RecordAction("TabOverview_DetachCell",
- original_model_->profile());
-
- detached_window_ = CreateDetachedWindow(
- location, model()->GetTabContentsAt(current_index_));
- detached_window_->Show();
-
- grid()->set_floating_index(-1);
- SetDetachedContents(model()->GetTabContentsAt(current_index_));
- if (model()->count() == 1) {
- // The model is going to be empty. Tell the host to move us offscreen.
- // NOTE: it would be nice to hide and destroy the window here but this
- // causes two problems: we'll stop getting events, and we don't want
- // to empty out the tabstrip as otherwise they may trigger Chrome to
- // exit.
- controller_->MoveOffscreen();
- hidden_browser_ = controller_->browser();
- gtk_widget_hide(GTK_WIDGET(static_cast<BrowserWindowGtk*>(
- hidden_browser_->window())->GetNativeHandle()));
- }
- modifying_model_ = true;
- model()->DetachTabContentsAt(current_index_);
- modifying_model_ = false;
-}
-
-void TabOverviewDragController::DropTab(const gfx::Point& location) {
- TabContents* contents = detached_tab_;
- SetDetachedContents(NULL);
-
- gfx::Point screen_loc(location);
- grid()->ConvertPointToScreen(grid(), &screen_loc);
- gfx::Rect window_bounds(screen_loc, browser_window_size_);
- Browser* new_browser =
- original_model_->delegate()->CreateNewStripWithContents(
- contents, window_bounds, DockInfo());
- new_browser->window()->Show();
-
- detached_window_->Close();
- detached_window_ = NULL;
-}
-
-void TabOverviewDragController::MoveDetachedWindow(
- const gfx::Point& location) {
- gfx::Point screen_loc = location;
- screen_loc.Offset(-x_offset_, -y_offset_);
- grid()->ConvertPointToScreen(grid(), &screen_loc);
- detached_window_->SetBounds(
- gfx::Rect(screen_loc,
- detached_window_->GetRootView()->GetPreferredSize()));
-
- // Notify the wm of the move.
- TabOverviewTypes::Message message;
- message.set_type(TabOverviewTypes::Message::WM_MOVE_FLOATING_TAB);
- message.set_param(0, x11_util::GetX11WindowFromGtkWidget(
- detached_window_->GetNativeView()));
- message.set_param(1, screen_loc.x() + x_offset_);
- message.set_param(2, screen_loc.y() + y_offset_);
- TabOverviewTypes::instance()->SendMessage(message);
-}
-
-views::Widget* TabOverviewDragController::CreateDetachedWindow(
- const gfx::Point& location,
- TabContents* tab_contents) {
- // TODO: wrap the cell in another view that provides a background.
- views::WidgetGtk* widget =
- new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
- widget->MakeTransparent();
- gfx::Point screen_loc = location;
- screen_loc.Offset(-x_offset_, -y_offset_);
- grid()->ConvertPointToScreen(grid(), &screen_loc);
- TabOverviewCell* cell = new TabOverviewCell();
- cell->set_preferred_size(
- gfx::Size(grid()->cell_width(), grid()->cell_height()));
- controller_->ConfigureCell(cell, tab_contents);
- widget->Init(NULL, gfx::Rect(screen_loc, cell->GetPreferredSize()));
- widget->GetRootView()->SetLayoutManager(new views::FillLayout());
- widget->GetRootView()->AddChildView(cell);
-
- std::vector<int> params(4);
- params[0] = screen_loc.x() + x_offset_;
- params[1] = screen_loc.y() + y_offset_;
- params[2] = x_offset_;
- params[3] = y_offset_;
- TabOverviewTypes::instance()->SetWindowType(
- widget->GetNativeView(),
- TabOverviewTypes::WINDOW_TYPE_CHROME_FLOATING_TAB,
- &params);
-
- return widget;
-}
-
-void TabOverviewDragController::SetDetachedContents(TabContents* tab) {
- if (detached_tab_) {
- registrar_.Remove(this,
- NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(detached_tab_));
- if (detached_tab_->delegate() == this)
- detached_tab_->set_delegate(original_delegate_);
- else
- DLOG(WARNING) << " delegate changed";
- }
- original_delegate_ = NULL;
- detached_tab_ = tab;
- if (tab) {
- registrar_.Add(this,
- NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab));
-
- // We need to be the delegate so we receive messages about stuff,
- // otherwise our dragged contents may be replaced and subsequently
- // collected/destroyed while the drag is in process, leading to
- // nasty crashes.
- original_delegate_ = tab->delegate();
- tab->set_delegate(this);
- }
-}
diff --git a/chrome/browser/views/tabs/tab_overview_drag_controller.h b/chrome/browser/views/tabs/tab_overview_drag_controller.h
deleted file mode 100644
index 4a8a2a0..0000000
--- a/chrome/browser/views/tabs/tab_overview_drag_controller.h
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_DRAG_CONTROLLER_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_DRAG_CONTROLLER_H_
-
-#include "base/gfx/point.h"
-#include "base/scoped_ptr.h"
-#include "chrome/browser/tab_contents/tab_contents_delegate.h"
-#include "chrome/common/notification_registrar.h"
-
-class Browser;
-class TabOverviewController;
-class TabOverviewGrid;
-class TabStripModel;
-
-namespace views {
-class Widget;
-}
-
-// TabOverviewDragController handles dragging cells in a TabOverviewGrid.
-// There are a couple of interesting states TabOverviewDragController may
-// be in:
-// . original_index_ == -1: indicates the drag wasn't valid (not over a cell),
-// or the drag is done (either committed or reverted).
-// . detached_tab_ != NULL: the user has dragged a tab outside the grid such
-// that a windows was created with the contents of
-// the tab.
-// . detached_tab_ == NULL: the user is dragging a cell around within the grid.
-//
-// TabOverviewGrid invokes Configure to prepare the controller. If this returns
-// true, then Drag is repeatedly invoked as the user drags the mouse around.
-// Finally CommitDrag is invoked if the user releases the mouse, or RevertDrag
-// if the drag is canceled some how.
-//
-// NOTE: all coordinates passed in are relative to the TabOverviewGrid.
-class TabOverviewDragController : public TabContentsDelegate,
- public NotificationObserver {
- public:
- explicit TabOverviewDragController(TabOverviewController* controller);
- ~TabOverviewDragController();
-
- // Sets whether the mouse is over a mini-window.
- void set_mouse_over_mini_window(bool over_mini_window) {
- mouse_over_mini_window_ = over_mini_window;
- }
-
- // Prepares the TabOverviewDragController for a drag. Returns true if over a
- // cell, false if the mouse isn't over a valid location.
- bool Configure(const gfx::Point& location);
-
- // Invoked as the user drags the mouse.
- void Drag(const gfx::Point& location);
-
- // Commits the drag, typically when the user releases the mouse.
- void CommitDrag(const gfx::Point& location);
-
- // Reverts the drag. Use true if the revert is the result of the tab being
- // destroyed.
- void RevertDrag(bool tab_destroyed);
-
- bool modifying_model() const { return modifying_model_; }
- TabOverviewGrid* grid() const;
- TabStripModel* model() const;
-
- // Overridden from NotificationObserver:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- // Overridden from TabContentsDelegate:
- virtual void OpenURLFromTab(TabContents* source,
- const GURL& url,
- const GURL& referrer,
- WindowOpenDisposition disposition,
- PageTransition::Type transition);
- virtual void NavigationStateChanged(const TabContents* source,
- unsigned changed_flags);
- virtual void AddNewContents(TabContents* source,
- TabContents* new_contents,
- WindowOpenDisposition disposition,
- const gfx::Rect& initial_pos,
- bool user_gesture);
- virtual void ActivateContents(TabContents* contents);
- virtual void LoadingStateChanged(TabContents* source);
- virtual void CloseContents(TabContents* source);
- virtual void MoveContents(TabContents* source, const gfx::Rect& pos);
- virtual bool IsPopup(TabContents* source);
- virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
- virtual void URLStarredChanged(TabContents* source, bool starred);
- virtual void UpdateTargetURL(TabContents* source, const GURL& url);
-
- private:
- // Invoked from Drag if the mouse has moved enough to trigger dragging.
- void DragCell(const gfx::Point& location);
-
- // Reattaches the detatched tab. |index| is the index into |model()| as to
- // where the tab should be attached.
- void Attach(int index);
-
- // Detaches the tab at |current_index_|.
- void Detach(const gfx::Point& location);
-
- // Drops the detached tab. This is invoked from |CommitDrag|.
- void DropTab(const gfx::Point& location);
-
- // Moves the detached window.
- void MoveDetachedWindow(const gfx::Point& location);
-
- // Creates and returns the detached window.
- views::Widget* CreateDetachedWindow(const gfx::Point& location,
- TabContents* contents);
-
- // Sets the detaches contents, installed/uninstalling listeners.
- void SetDetachedContents(TabContents* tab);
-
- TabOverviewController* controller_;
-
- // The model the drag started from. This needs to be cached as the grid may
- // end up showing a different model if the user drags over another window.
- TabStripModel* original_model_;
-
- // The index the tab has been dragged to. This is initially the index the
- // user pressed the mouse at, but changes as the user drags the tab around.
- int current_index_;
-
- // The original index the tab was at. If -1 it means the drag is invalid or
- // done. See description above class for more details.
- int original_index_;
-
- // The tab being dragged. This is only non-NULL if the tab has been detached.
- TabContents* detached_tab_;
-
- // If detached_tab_ is non-null, this is it's delegate before we set
- // ourselves as the delegate.
- TabContentsDelegate* original_delegate_;
-
- // The origin of the click.
- gfx::Point origin_;
-
- // Offset of the initial mouse location relative to the cell at
- // original_index_.
- int x_offset_;
- int y_offset_;
-
- // Has the user started dragging?
- bool dragging_;
-
- // If true, we're modifying the model. This is used to avoid cancelling the
- // drag when the model changes.
- bool modifying_model_;
-
- // Handles registering for notifications.
- NotificationRegistrar registrar_;
-
- // Once a tab is detached a window is created containing a cell and moved
- // around; this is that window.
- views::Widget* detached_window_;
-
- // When a tab is detached from a browser with a single tab we hide the
- // browser. If this is non-null it means a single tab has been detached
- // and this is the browser it was detached from.
- Browser* hidden_browser_;
-
- // Whether the mouse is over a mini window.
- bool mouse_over_mini_window_;
-
- // Size of the browser window. Cached in case browser() becomes NULL (as
- // happens when the user drags over a region that shouldn't show the tab
- // overview).
- gfx::Size browser_window_size_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewDragController);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_DRAG_CONTROLLER_H_
diff --git a/chrome/browser/views/tabs/tab_overview_grid.cc b/chrome/browser/views/tabs/tab_overview_grid.cc
deleted file mode 100644
index 35bd116..0000000
--- a/chrome/browser/views/tabs/tab_overview_grid.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_grid.h"
-
-#include "chrome/browser/views/tabs/tab_overview_cell.h"
-#include "chrome/browser/views/tabs/tab_overview_controller.h"
-#include "chrome/browser/views/tabs/tab_overview_drag_controller.h"
-#include "views/screen.h"
-
-TabOverviewGrid::TabOverviewGrid(TabOverviewController* controller)
- : controller_(controller) {
-}
-
-TabOverviewGrid::~TabOverviewGrid() {
-}
-
-bool TabOverviewGrid::modifying_model() const {
- return drag_controller_.get() && drag_controller_->modifying_model();
-}
-
-TabOverviewCell* TabOverviewGrid::GetTabOverviewCellAt(int index) {
- return static_cast<TabOverviewCell*>(GetChildViewAt(index));
-}
-
-TabOverviewDragController* TabOverviewGrid::drag_controller() const {
- return drag_controller_.get();
-}
-
-void TabOverviewGrid::CancelDrag() {
- drag_controller_.reset(NULL);
-}
-
-void TabOverviewGrid::UpdateDragController() {
- if (drag_controller_.get()) {
- gfx::Point mouse_loc = views::Screen::GetCursorScreenPoint();
- ConvertPointToView(NULL, this, &mouse_loc);
- drag_controller_->Drag(mouse_loc);
- }
-}
-
-bool TabOverviewGrid::OnMousePressed(const views::MouseEvent& event) {
- if (drag_controller_.get())
- return true;
-
- if (!event.IsLeftMouseButton())
- return false;
-
- drag_controller_.reset(new TabOverviewDragController(controller_));
- if (!drag_controller_->Configure(event.location())) {
- drag_controller_.reset(NULL);
- return false;
- }
- return true;
-}
-
-bool TabOverviewGrid::OnMouseDragged(const views::MouseEvent& event) {
- if (!drag_controller_.get())
- return false;
-
- drag_controller_->Drag(event.location());
- return true;
-}
-
-void TabOverviewGrid::OnMouseReleased(const views::MouseEvent& event,
- bool canceled) {
- if (!drag_controller_.get())
- return;
-
- if (canceled)
- drag_controller_->RevertDrag(false);
- else
- drag_controller_->CommitDrag(event.location());
- drag_controller_.reset(NULL);
-}
-
-void TabOverviewGrid::AnimationEnded(const Animation* animation) {
- Grid::AnimationEnded(animation);
- controller_->GridAnimationEnded();
-}
-
-void TabOverviewGrid::AnimationProgressed(const Animation* animation) {
- Grid::AnimationProgressed(animation);
- controller_->GridAnimationProgressed();
-}
-
-void TabOverviewGrid::AnimationCanceled(const Animation* animation) {
- Grid::AnimationCanceled(animation);
- controller_->GridAnimationCanceled();
-}
diff --git a/chrome/browser/views/tabs/tab_overview_grid.h b/chrome/browser/views/tabs/tab_overview_grid.h
deleted file mode 100644
index 52cf27f..0000000
--- a/chrome/browser/views/tabs/tab_overview_grid.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_GRID_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_GRID_H_
-
-#include "base/scoped_ptr.h"
-#include "chrome/browser/views/tabs/grid.h"
-
-class TabOverviewCell;
-class TabOverviewController;
-class TabOverviewDragController;
-
-// TabOverviewGrid is used to provide a grid view of the contents of a tab
-// strip model. Each cell of the grid is a TabOverviewCell. TabOverviewGrids
-// primary responsibility is to forward events to TabOverviewDragController.
-class TabOverviewGrid : public Grid {
- public:
- explicit TabOverviewGrid(TabOverviewController* controller);
- virtual ~TabOverviewGrid();
-
- // Returns true if a drag is underway and the drag is in the process of
- // modifying the tab strip model.
- bool modifying_model() const;
-
- // Returns the TabOverviewCell at the specified index.
- TabOverviewCell* GetTabOverviewCellAt(int index);
-
- // Returns the TabOverviewDragController. This is NULL if a drag is not
- // underway.
- TabOverviewDragController* drag_controller() const;
-
- // Cancels the drag. Does nothing if a drag is not underway.
- void CancelDrag();
-
- // If a drag is under way, this invokes Drag on the DragController with the
- // current position of the mouse.
- void UpdateDragController();
-
- // View overrides.
- virtual bool OnMousePressed(const views::MouseEvent& event);
- virtual bool OnMouseDragged(const views::MouseEvent& event);
- virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled);
-
- // AnimationDelegate overrides.
- virtual void AnimationEnded(const Animation* animation);
- virtual void AnimationProgressed(const Animation* animation);
- virtual void AnimationCanceled(const Animation* animation);
-
- private:
- TabOverviewController* controller_;
-
- scoped_ptr<TabOverviewDragController> drag_controller_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewGrid);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_GRID_H_
diff --git a/chrome/browser/views/tabs/tab_overview_message_listener.cc b/chrome/browser/views/tabs/tab_overview_message_listener.cc
deleted file mode 100644
index 3222d21..0000000
--- a/chrome/browser/views/tabs/tab_overview_message_listener.cc
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_message_listener.h"
-
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_list.h"
-#if defined(TOOLKIT_VIEWS)
-#include "chrome/browser/views/frame/browser_view.h"
-#else
-#include "chrome/browser/gtk/browser_window_gtk.h"
-#endif
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/views/new_browser_window_widget.h"
-#include "chrome/browser/views/tabs/tab_overview_controller.h"
-#include "chrome/common/x11_util.h"
-
-// static
-TabOverviewMessageListener* TabOverviewMessageListener::instance() {
- static TabOverviewMessageListener* instance = NULL;
- if (!instance) {
- instance = Singleton<TabOverviewMessageListener>::get();
- MessageLoopForUI::current()->AddObserver(instance);
- }
- return instance;
-}
-
-#if defined(TOOLKIT_VIEWS)
-// static
-BrowserView* TabOverviewMessageListener::GetBrowserViewForGdkWindow(
- GdkWindow* gdk_window) {
- gpointer data = NULL;
- gdk_window_get_user_data(gdk_window, &data);
- GtkWidget* widget = reinterpret_cast<GtkWidget*>(data);
- if (widget) {
- GtkWindow* gtk_window = GTK_WINDOW(widget);
- return BrowserView::GetBrowserViewForNativeWindow(gtk_window);
- } else {
- return NULL;
- }
-}
-#endif
-
-void TabOverviewMessageListener::WillProcessEvent(GdkEvent* event) {
-}
-
-void TabOverviewMessageListener::DidProcessEvent(GdkEvent* event) {
- if (event->type == GDK_CLIENT_EVENT) {
- TabOverviewTypes::Message message;
- GdkEventClient* client_event = reinterpret_cast<GdkEventClient*>(event);
- TabOverviewTypes* types = TabOverviewTypes::instance();
- if (types->DecodeMessage(*client_event, &message))
- ProcessMessage(message, client_event->window);
- else
- types->HandleNonChromeClientMessageEvent(*client_event);
- }
-}
-
-TabOverviewMessageListener::TabOverviewMessageListener() {
-}
-
-TabOverviewMessageListener::~TabOverviewMessageListener() {
-}
-
-void TabOverviewMessageListener::ProcessMessage(
- const TabOverviewTypes::Message& message,
- GdkWindow* window) {
- switch (message.type()) {
- case TabOverviewTypes::Message::CHROME_SET_TAB_SUMMARY_VISIBILITY: {
- if (message.param(0) == 0) {
- HideOverview();
- } else {
-#if defined(TOOLKIT_VIEWS)
- BrowserView* browser_window = GetBrowserViewForGdkWindow(window);
-#else
- BrowserWindowGtk* browser_window =
- BrowserWindowGtk::GetBrowserWindowForNativeWindow(
- BrowserWindowGtk::GetBrowserWindowForXID(
- x11_util::GetX11WindowFromGdkWindow(window)));
-#endif
- if (browser_window)
- ShowOverview(browser_window->browser(), message.param(1));
- else
- HideOverview();
- }
- break;
- }
-
- case TabOverviewTypes::Message::CHROME_NOTIFY_LAYOUT_MODE: {
- if (message.param(0) == 0) {
- new_browser_window_.reset(NULL);
- controller_.reset(NULL);
- } else if (BrowserList::size() > 0) {
- Browser* browser = *BrowserList::begin();
- controller_.reset(new TabOverviewController(
- browser->window()->GetRestoredBounds().origin()));
- new_browser_window_.reset(
- new NewBrowserWindowWidget(browser->profile()));
- }
- break;
- }
-
- case TabOverviewTypes::Message::CHROME_NOTIFY_FLOATING_TAB_OVER_TOPLEVEL: {
- if (!controller_.get())
- return;
-
- bool over_mini_window = message.param(1) == 1;
- controller_->SetMouseOverMiniWindow(over_mini_window);
- if (!over_mini_window)
- return;
-
- // Over a mini-window, make sure the controller is showing the contents
- // of the browser the mouse is over.
-#if defined(TOOLKIT_VIEWS)
- BrowserView* browser_window = GetBrowserViewForGdkWindow(
- gdk_window_lookup(message.param(0)));
-#else
- BrowserWindowGtk* browser_window =
- BrowserWindowGtk::GetBrowserWindowForNativeWindow(
- BrowserWindowGtk::GetBrowserWindowForXID(message.param(0)));
-#endif
- if (!browser_window)
- return;
-
- if (controller_->browser()->window() == browser_window)
- return;
-
- TabOverviewTypes::Message select_message;
- select_message.set_type(TabOverviewTypes::Message::WM_MOVE_FLOATING_TAB);
- select_message.set_param(0, message.param(1));
- TabOverviewTypes::instance()->SendMessage(select_message);
-
- UserMetrics::RecordAction("TabOverview_DragOverMiniWindow",
- browser_window->browser()->profile());
- }
-
- default:
- break;
- }
-}
-
-void TabOverviewMessageListener::ShowOverview(Browser* browser,
- int horizontal_center) {
- if (!controller_.get()) {
- controller_.reset(new TabOverviewController(
- browser->window()->GetRestoredBounds().origin()));
- }
- controller_->SetBrowser(browser, horizontal_center);
- controller_->Show();
-}
-
-void TabOverviewMessageListener::HideOverview() {
- controller_->SetBrowser(NULL, -1);
-}
diff --git a/chrome/browser/views/tabs/tab_overview_message_listener.h b/chrome/browser/views/tabs/tab_overview_message_listener.h
deleted file mode 100644
index 4075222..0000000
--- a/chrome/browser/views/tabs/tab_overview_message_listener.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_MESSAGE_LISTENER_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_MESSAGE_LISTENER_H_
-
-#include <gtk/gtk.h>
-
-#include "base/message_loop.h"
-#include "base/scoped_ptr.h"
-#include "base/singleton.h"
-#include "chrome/browser/views/tabs/tab_overview_types.h"
-
-class Browser;
-#if defined(TOOLKIT_VIEWS)
-class BrowserView;
-#endif
-class NewBrowserWindowWidget;
-class TabOverviewController;
-
-// TabOverviewMessageListener listens for messages, showing/hiding the tab
-// overview as necessary. TabOverviewMessageListener is created early on by
-// browser init and only one instance ever exists.
-class TabOverviewMessageListener : public MessageLoopForUI::Observer {
- public:
- static TabOverviewMessageListener* instance();
-
- // MessageLoopForUI::Observer overrides.
- virtual void WillProcessEvent(GdkEvent* event);
- virtual void DidProcessEvent(GdkEvent* event);
-
- private:
- friend struct DefaultSingletonTraits<TabOverviewMessageListener>;
-
-#if defined(TOOLKIT_VIEWS)
- // Returns a BrowserView that corresponds to given gdk_window.
- static BrowserView* GetBrowserViewForGdkWindow(GdkWindow* gdk_window);
-#endif
-
- TabOverviewMessageListener();
- ~TabOverviewMessageListener();
-
- // Invoked when a valid TabOverviewTypes::Message is found on the message
- // loop..
- void ProcessMessage(const TabOverviewTypes::Message& message,
- GdkWindow* window);
-
- // Shows the tab overview for |browser|.
- void ShowOverview(Browser* browser, int horizontal_center);
-
- // Hids the tab overview.
- void HideOverview();
-
- // If non-null tab overview is showing.
- scoped_ptr<TabOverviewController> controller_;
-
- // Non-null while in tab-overview mode.
- scoped_ptr<NewBrowserWindowWidget> new_browser_window_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewMessageListener);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_MESSAGE_LISTENER_H_
diff --git a/chrome/browser/views/tabs/tab_overview_types.cc b/chrome/browser/views/tabs/tab_overview_types.cc
deleted file mode 100644
index 6ce76a3..0000000
--- a/chrome/browser/views/tabs/tab_overview_types.cc
+++ /dev/null
@@ -1,250 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/views/tabs/tab_overview_types.h"
-
-#include <gdk/gdkx.h>
-extern "C" {
-#include <X11/Xlib.h>
-}
-
-#include "base/logging.h"
-#include "base/singleton.h"
-#include "base/scoped_ptr.h"
-#include "chrome/common/x11_util.h"
-
-namespace {
-
-// A value from the Atom enum and the actual name that should be used to
-// look up its ID on the X server.
-struct AtomInfo {
- TabOverviewTypes::AtomType atom;
- const char* name;
-};
-
-// Each value from the Atom enum must be present here.
-static const AtomInfo kAtomInfos[] = {
- { TabOverviewTypes::ATOM_CHROME_WINDOW_TYPE,
- "_CHROME_WINDOW_TYPE" },
- { TabOverviewTypes::ATOM_CHROME_WM_MESSAGE,
- "_CHROME_WM_MESSAGE" },
- { TabOverviewTypes::ATOM_MANAGER,
- "MANAGER" },
- { TabOverviewTypes::ATOM_NET_SUPPORTING_WM_CHECK,
- "_NET_SUPPORTING_WM_CHECK" },
- { TabOverviewTypes::ATOM_NET_WM_NAME,
- "_NET_WM_NAME" },
- { TabOverviewTypes::ATOM_PRIMARY,
- "PRIMARY" },
- { TabOverviewTypes::ATOM_STRING,
- "STRING" },
- { TabOverviewTypes::ATOM_UTF8_STRING,
- "UTF8_STRING" },
- { TabOverviewTypes::ATOM_WM_NORMAL_HINTS,
- "WM_NORMAL_HINTS" },
- { TabOverviewTypes::ATOM_WM_S0,
- "WM_S0" },
- { TabOverviewTypes::ATOM_WM_STATE,
- "WM_STATE" },
- { TabOverviewTypes::ATOM_WM_TRANSIENT_FOR,
- "WM_TRANSIENT_FOR" },
- { TabOverviewTypes::ATOM_WM_SYSTEM_METRICS,
- "WM_SYSTEM_METRICS" },
-};
-
-bool SetIntProperty(XID xid, Atom xatom, const std::vector<int>& values) {
- DCHECK(!values.empty());
-
- // TODO: Trap errors and return false on failure.
- XChangeProperty(x11_util::GetXDisplay(),
- xid,
- xatom,
- xatom,
- 32, // size in bits of items in 'value'
- PropModeReplace,
- reinterpret_cast<const unsigned char*>(&values.front()),
- values.size()); // num items
- XFlush(x11_util::GetXDisplay());
- return true;
-}
-
-} // namespace
-
-// static
-TabOverviewTypes* TabOverviewTypes::instance() {
- static TabOverviewTypes* instance = NULL;
- if (!instance)
- instance = Singleton<TabOverviewTypes>::get();
- return instance;
-}
-
-bool TabOverviewTypes::SetWindowType(
- GtkWidget* widget,
- WindowType type,
- const std::vector<int>* params) {
- std::vector<int> values;
- values.push_back(type);
- if (params)
- values.insert(values.end(), params->begin(), params->end());
- return SetIntProperty(x11_util::GetX11WindowFromGtkWidget(widget),
- type_to_atom_[ATOM_CHROME_WINDOW_TYPE], values);
-}
-
-void TabOverviewTypes::SendMessage(const Message& msg) {
- XEvent e;
- e.xclient.type = ClientMessage;
- e.xclient.window = wm_;
- e.xclient.message_type = type_to_atom_[ATOM_CHROME_WM_MESSAGE];
- e.xclient.format = 32; // 32-bit values
- e.xclient.data.l[0] = msg.type();
-
- // XClientMessageEvent only gives us five 32-bit items, and we're using
- // the first one for our message type.
- DCHECK_LE(msg.max_params(), 4);
- for (int i = 0; i < msg.max_params(); ++i)
- e.xclient.data.l[i+1] = msg.param(i);
-
- XSendEvent(x11_util::GetXDisplay(),
- wm_,
- False, // propagate
- 0, // empty event mask
- &e);
-}
-
-bool TabOverviewTypes::DecodeMessage(const GdkEventClient& event,
- Message* msg) {
- if (wm_message_atom_ != gdk_x11_atom_to_xatom(event.message_type))
- return false;
-
- if (event.data_format != 32) {
- DLOG(WARNING) << "Ignoring ClientEventMessage with invalid bit "
- << "format " << event.data_format
- << " (expected 32-bit values)";
- return false;
- }
-
- msg->set_type(static_cast<Message::Type>(event.data.l[0]));
- if (msg->type() < 0 || msg->type() >= Message::kNumTypes) {
- DLOG(WARNING) << "Ignoring ClientEventMessage with invalid message "
- << "type " << msg->type();
- return false;
- }
-
- // XClientMessageEvent only gives us five 32-bit items, and we're using
- // the first one for our message type.
- DCHECK_LE(msg->max_params(), 4);
- for (int i = 0; i < msg->max_params(); ++i)
- msg->set_param(i, event.data.l[i+1]); // l[0] contains message type
-
- return true;
-}
-
-bool TabOverviewTypes::DecodeStringMessage(const GdkEventProperty& event,
- std::string* msg) {
- DCHECK(NULL != msg);
- if (type_to_atom_[ATOM_WM_SYSTEM_METRICS] !=
- gdk_x11_atom_to_xatom(event.atom))
- return false;
-
- DLOG(WARNING) << "Got property change notification for system metrics.";
- if (GDK_PROPERTY_DELETE == event.state) {
- DLOG(WARNING) << "Ignoring delete EventPropertyNotification";
- return false;
- }
-
- // We will be using DBus for this communication in the future, so I don't
- // really worry right now that we could generate more than 1KB here.
- // Also, I use "long" rather than int64 because that is what X expects.
- long acceptable_bytes = 1024;
- Atom actual_type;
- int actual_format;
- unsigned long num_items, bytes_left;
- unsigned char *output;
- if (Success != XGetWindowProperty(x11_util::GetXDisplay(),
- GDK_WINDOW_XID(event.window),
- type_to_atom_[ATOM_WM_SYSTEM_METRICS],
- 0,
- acceptable_bytes,
- false,
- AnyPropertyType,
- &actual_type,
- &actual_format,
- &num_items,
- &bytes_left,
- &output)) {
- DLOG(WARNING) << "Could not read system metrics property from X.";
- return false;
- }
- if (actual_format == 0) {
- DLOG(WARNING) << "System Metrics property not set.";
- return false;
- }
- if (actual_format != 8) {
- DLOG(WARNING) << "Message was not encoded as a string of bytes...";
- return false;
- }
- if (bytes_left != 0) {
- DLOG(ERROR) << "We wanted all the bytes at once...";
- return false;
- }
- msg->assign(reinterpret_cast<char*>(output), num_items);
- XFree(output);
- return true;
-}
-
-void TabOverviewTypes::HandleNonChromeClientMessageEvent(
- const GdkEventClient& event) {
- // Only do these lookups once; they should never change.
- static GdkAtom manager_gdk_atom =
- gdk_x11_xatom_to_atom(type_to_atom_[ATOM_MANAGER]);
- static Atom wm_s0_atom = type_to_atom_[ATOM_WM_S0];
-
- if (event.message_type == manager_gdk_atom &&
- static_cast<Atom>(event.data.l[1]) == wm_s0_atom) {
- InitWmInfo();
- }
-}
-
-TabOverviewTypes::TabOverviewTypes() {
- scoped_array<char*> names(new char*[kNumAtoms]);
- scoped_array<Atom> atoms(new Atom[kNumAtoms]);
-
- for (int i = 0; i < kNumAtoms; ++i) {
- // Need to const_cast because XInternAtoms() wants a char**.
- names[i] = const_cast<char*>(kAtomInfos[i].name);
- }
-
- XInternAtoms(x11_util::GetXDisplay(), names.get(), kNumAtoms,
- False, // only_if_exists
- atoms.get());
-
- for (int i = 0; i < kNumAtoms; ++i) {
- type_to_atom_[kAtomInfos[i].atom] = atoms[i];
- atom_to_string_[atoms[i]] = kAtomInfos[i].name;
- }
-
- wm_message_atom_ = type_to_atom_[ATOM_CHROME_WM_MESSAGE];
-
- // Make sure that we're selecting structure changes on the root window;
- // the window manager uses StructureNotifyMask when sending the ClientMessage
- // event to announce that it's taken the manager selection.
- GdkWindow* root = gdk_get_default_root_window();
- GdkEventMask event_mask = gdk_window_get_events(root);
- gdk_window_set_events(
- root, static_cast<GdkEventMask>(event_mask | GDK_STRUCTURE_MASK));
-
- InitWmInfo();
-}
-
-void TabOverviewTypes::InitWmInfo() {
- wm_ = XGetSelectionOwner(x11_util::GetXDisplay(), type_to_atom_[ATOM_WM_S0]);
-
- // Let the window manager know which version of the IPC messages we support.
- Message msg(Message::WM_NOTIFY_IPC_VERSION);
- // TODO: The version number is the latest listed in tab_overview_types.h --
- // ideally, once this header is shared between Chrome and the Chrome OS window
- // manager, we'll just define the version statically in the header.
- msg.set_param(0, 1);
- SendMessage(msg);
-}
diff --git a/chrome/browser/views/tabs/tab_overview_types.h b/chrome/browser/views/tabs/tab_overview_types.h
deleted file mode 100644
index e19fdff..0000000
--- a/chrome/browser/views/tabs/tab_overview_types.h
+++ /dev/null
@@ -1,286 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_TYPES_H_
-#define CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_TYPES_H_
-
-#include <gtk/gtk.h>
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/singleton.h"
-
-typedef unsigned long Atom;
-typedef unsigned long XID;
-
-// TODO(sky): move and rename.
-class TabOverviewTypes {
- public:
- enum AtomType {
- ATOM_CHROME_WINDOW_TYPE = 0,
- ATOM_CHROME_WM_MESSAGE,
- ATOM_MANAGER,
- ATOM_NET_SUPPORTING_WM_CHECK,
- ATOM_NET_WM_NAME,
- ATOM_PRIMARY,
- ATOM_STRING,
- ATOM_UTF8_STRING,
- ATOM_WM_NORMAL_HINTS,
- ATOM_WM_S0,
- ATOM_WM_STATE,
- ATOM_WM_TRANSIENT_FOR,
- ATOM_WM_SYSTEM_METRICS,
- kNumAtoms,
- };
-
- enum WindowType {
- WINDOW_TYPE_UNKNOWN = 0,
-
- // A top-level Chrome window.
- WINDOW_TYPE_CHROME_TOPLEVEL,
-
- // A window showing scaled-down views of all of the tabs within a
- // Chrome window.
- WINDOW_TYPE_CHROME_TAB_SUMMARY,
-
- // A tab that's been detached from a Chrome window and is currently
- // being dragged.
- // param[0]: Cursor's initial X position at the start of the drag
- // param[1]: Cursor's initial Y position
- // param[2]: X component of cursor's offset from upper-left corner of
- // tab at start of drag
- // param[3]: Y component of cursor's offset
- WINDOW_TYPE_CHROME_FLOATING_TAB,
-
- // The contents of a popup window.
- // param[0]: X ID of associated titlebar, which must be mapped before
- // its content
- // param[1]: Initial state for panel (0 is collapsed, 1 is expanded)
- WINDOW_TYPE_CHROME_PANEL_CONTENT,
-
- // A small window representing a collapsed panel in the panel bar and
- // drawn above the panel when it's expanded.
- WINDOW_TYPE_CHROME_PANEL_TITLEBAR,
-
- // A small window that when clicked creates a new browser window.
- WINDOW_TYPE_CREATE_BROWSER_WINDOW,
-
- // A Chrome info bubble (e.g. the bookmark bubble). These are
- // transient RGBA windows; we skip the usual transient behavior of
- // centering them over their owner and omit drawing a drop shadow.
- WINDOW_TYPE_CHROME_INFO_BUBBLE,
-
- kNumWindowTypes,
- };
-
- struct Message {
- public:
- // NOTE: Don't remove values from this enum; it is shared between
- // Chrome and the window manager.
- enum Type {
- UNKNOWN = 0,
-
- // Notify Chrome when a floating tab has entered or left a tab
- // summary window. Sent to the summary window.
- // param[0]: X ID of the floating tab window
- // param[1]: state (0 means left, 1 means entered or currently in)
- // param[2]: X coordinate relative to summary window
- // param[3]: Y coordinate
- CHROME_NOTIFY_FLOATING_TAB_OVER_TAB_SUMMARY,
-
- // Notify Chrome when a floating tab has entered or left a top-level
- // window. Sent to the window being entered/left.
- // param[0]: X ID of the floating tab window
- // param[1]: state (0 means left, 1 means entered)
- CHROME_NOTIFY_FLOATING_TAB_OVER_TOPLEVEL,
-
- // Instruct a top-level Chrome window to change the visibility of its
- // tab summary window.
- // param[0]: desired visibility (0 means hide, 1 means show)
- // param[1]: X position (relative to the left edge of the root
- // window) of the center of the top-level window. Only
- // relevant for "show" messages
- CHROME_SET_TAB_SUMMARY_VISIBILITY,
-
- // Tell the WM to collapse or expand a panel.
- // param[0]: X ID of the panel window
- // param[1]: desired state (0 means collapsed, 1 means expanded)
- WM_SET_PANEL_STATE,
-
- // Notify Chrome that the panel state has changed. Sent to the panel
- // window.
- // param[0]: new state (0 means collapsed, 1 means expanded)
- CHROME_NOTIFY_PANEL_STATE,
-
- // Instruct the WM to move a floating tab. The passed-in position is
- // that of the cursor; the tab's composited window is displaced based
- // on the cursor's offset from the upper-left corner of the tab at
- // the start of the drag.
- // param[0]: X ID of the floating tab window
- // param[1]: X coordinate to which the tab should be moved
- // param[2]: Y coordinate
- WM_MOVE_FLOATING_TAB,
-
- // Notify the WM that a panel has been dragged.
- // param[0]: X ID of the panel's content window
- // param[1]: X coordinate to which the upper-right corner of the
- // panel's titlebar window was dragged
- // param[2]: Y coordinate to which the upper-right corner of the
- // panel's titlebar window was dragged
- // Note: The point given is actually that of one pixel to the right
- // of the upper-right corner of the titlebar window. For example, a
- // no-op move message for a 10-pixel wide titlebar whose upper-left
- // point is at (0, 0) would contain the X and Y paremeters (10, 0):
- // in other words, the position of the titlebar's upper-left point
- // plus its width. This is intended to make both the Chrome and WM
- // side of things simpler and to avoid some easy-to-make off-by-one
- // errors.
- WM_NOTIFY_PANEL_DRAGGED,
-
- // Notify the WM that the panel drag is complete (that is, the mouse
- // button has been released).
- // param[0]: X ID of the panel's content window
- WM_NOTIFY_PANEL_DRAG_COMPLETE,
-
- // Deprecated. Send a _NET_ACTIVE_WINDOW client message to focus a window
- // instead (e.g. using gtk_window_present()).
- DEPRECATED_WM_FOCUS_WINDOW,
-
- // Notify Chrome that the layout mode (for example, overview or
- // focused) has changed.
- // param[0]: new mode (0 means focused, 1 means overview)
- CHROME_NOTIFY_LAYOUT_MODE,
-
- // Instruct the WM to enter overview mode.
- // param[0]: X ID of the window to show the tab overview for.
- WM_SWITCH_TO_OVERVIEW_MODE,
-
- // Let the WM know which version of this file Chrome is using. It's
- // difficult to make changes synchronously to Chrome and the WM (our
- // build scripts can use a locally-built Chromium, the latest one
- // from the buildbot, or an older hardcoded version), so it's useful
- // to be able to maintain compatibility in the WM with versions of
- // Chrome that exhibit older behavior.
- //
- // Chrome should send a message to the WM at startup containing the
- // latest version from the list below. For backwards compatibility,
- // the WM assumes version 0 if it doesn't receive a message. Here
- // are the changes that have been made in successive versions of the
- // protocol:
- //
- // 1: WM_NOTIFY_PANEL_DRAGGED contains the position of the
- // upper-right, rather than upper-left, corner of of the titlebar
- // window
- //
- // TODO: The latest version should be hardcoded in this file once the
- // file is being shared between Chrome and the WM so Chrome can just
- // pull it from there. Better yet, the message could be sent
- // automatically in WmIpc's c'tor.
- //
- // param[0]: version of this protocol currently supported
- WM_NOTIFY_IPC_VERSION,
-
- kNumTypes,
- };
-
- Message() {
- Init(UNKNOWN);
- }
- explicit Message(Type type) {
- Init(type);
- }
-
- Type type() const { return type_; }
- void set_type(Type type) { type_ = type; }
-
- inline int max_params() const {
- return arraysize(params_);
- }
- long param(int index) const {
- DCHECK_GE(index, 0);
- DCHECK_LT(index, max_params());
- return params_[index];
- }
- void set_param(int index, long value) {
- DCHECK_GE(index, 0);
- DCHECK_LT(index, max_params());
- params_[index] = value;
- }
-
- private:
- // Common initialization code shared between constructors.
- void Init(Type type) {
- set_type(type);
- for (int i = 0; i < max_params(); ++i) {
- set_param(i, 0);
- }
- }
-
- // Type of message that was sent.
- Type type_;
-
- // Type-specific data. This is bounded by the number of 32-bit values
- // that we can pack into a ClientMessageEvent -- it holds five, but we
- // use the first one to store the message type.
- long params_[4];
- };
-
- // Returns the single instance of TabOverviewTypes.
- static TabOverviewTypes* instance();
-
- // Get or set a property describing a window's type. Type-specific
- // parameters may also be supplied ('params' is mandatory for
- // GetWindowType() but optional for SetWindowType()). The caller is
- // responsible for trapping errors from the X server.
- // TODO: Trap these ourselves.
- bool SetWindowType(GtkWidget* widget,
- WindowType type,
- const std::vector<int>* params);
-
- // Sends a message to the WM.
- void SendMessage(const Message& msg);
-
- // If |event| is a valid Message it is decoded into |msg| and true is
- // returned. If false is returned, |event| is not a valid Message.
- bool DecodeMessage(const GdkEventClient& event, Message* msg);
-
- // If |event| is a valid StringMessage it is decoded into |msg| and true is
- // returned. If false is returned, |event| is not a valid StringMessage.
- bool DecodeStringMessage(const GdkEventProperty& event, std::string* msg);
-
- // Handle ClientMessage events that weren't decodable using DecodeMessage().
- // Specifically, this catches messages about the WM_S0 selection that get sent
- // when a window manager process starts (so that we can re-run InitWmInfo()).
- // See ICCCM 2.8 for more info about MANAGER selections.
- void HandleNonChromeClientMessageEvent(const GdkEventClient& event);
-
- private:
- friend struct DefaultSingletonTraits<TabOverviewTypes>;
-
- TabOverviewTypes();
-
- // Initialize 'wm_' and send the window manager a message telling it the
- // version of the IPC protocol that we support. This is called in our
- // constructor, but needs to be re-run if the window manager gets restarted.
- void InitWmInfo();
-
- // Maps from our Atom enum to the X server's atom IDs and from the
- // server's IDs to atoms' string names. These maps aren't necessarily in
- // sync; 'atom_to_xatom_' is constant after the constructor finishes but
- // GetName() caches additional string mappings in 'xatom_to_string_'.
- std::map<AtomType, Atom> type_to_atom_;
- std::map<Atom, std::string> atom_to_string_;
-
- // Cached value of type_to_atom_[ATOM_CHROME_WM_MESSAGE].
- Atom wm_message_atom_;
-
- // Handle to the wm. Used for sending messages.
- XID wm_;
-
- DISALLOW_COPY_AND_ASSIGN(TabOverviewTypes);
-};
-
-#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_TYPES_H_