diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-16 20:23:58 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-16 20:23:58 +0000 |
commit | 8374eafe188529606256db18fe92ae4f29d736cf (patch) | |
tree | d371f2079d236698a898d960703f06390093c5d4 | |
parent | 09b8f82f39b2e3613a4518d9390004522e432063 (diff) | |
download | chromium_src-8374eafe188529606256db18fe92ae4f29d736cf.zip chromium_src-8374eafe188529606256db18fe92ae4f29d736cf.tar.gz chromium_src-8374eafe188529606256db18fe92ae4f29d736cf.tar.bz2 |
Improved tab overview animations with better animation and wiring to
message loop.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/126185
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18523 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_init.cc | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 9 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 2 | ||||
-rw-r--r-- | chrome/browser/views/tabs/grid.cc | 39 | ||||
-rw-r--r-- | chrome/browser/views/tabs/grid.h | 15 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_container.cc | 5 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_container.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_controller.cc | 110 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_controller.h | 47 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_drag_controller.cc | 15 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_grid.cc | 24 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_grid.h | 9 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_message_listener.cc | 76 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_overview_message_listener.h | 52 | ||||
-rw-r--r-- | chrome/chrome.gyp | 12 | ||||
-rw-r--r-- | views/screen_gtk.cc | 2 |
16 files changed, 376 insertions, 57 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 5833a13..e9690b5 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -60,6 +60,10 @@ #include "base/win_util.h" #endif +#if defined(LINUX2) +#include "chrome/browser/views/tabs/tab_overview_message_listener.h" +#endif + namespace { class SetAsDefaultBrowserTask : public Task { @@ -336,6 +340,12 @@ bool LaunchBrowser(const CommandLine& command_line, Profile* profile, *return_code = ResultCodes::INVALID_CMDLINE_URL; return false; } + +#if defined(LINUX2) + // Create the TabOverviewMessageListener so that it can listen for messages + // regardless of what window has focus. + TabOverviewMessageListener::instance(); +#endif return true; } diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index d3107f1..3a47e6c 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -44,6 +44,10 @@ #include "chrome/common/pref_service.h" #include "grit/theme_resources.h" +#if defined(LINUX2) +#include "chrome/browser/views/tabs/tab_overview_types.h" +#endif + namespace { // The number of milliseconds between loading animation frames. @@ -414,6 +418,11 @@ gboolean BrowserWindowGtk::OnContentAreaExpose(GtkWidget* widget, void BrowserWindowGtk::Show() { gtk_widget_show(GTK_WIDGET(window_)); +#if defined(LINUX2) + TabOverviewTypes::instance()->SetWindowType( + GTK_WIDGET(window_), TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, + NULL); +#endif } void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 850431d..cbc8b08 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -43,6 +43,8 @@ class BrowserWindowGtk : public BrowserWindow, explicit BrowserWindowGtk(Browser* browser); virtual ~BrowserWindowGtk(); + Browser* browser() const { return browser_.get(); } + // Process a keyboard input and try to find an accelerator for it. void HandleAccelerator(guint keyval, GdkModifierType modifier); diff --git a/chrome/browser/views/tabs/grid.cc b/chrome/browser/views/tabs/grid.cc index ae17bf9..0f3876e 100644 --- a/chrome/browser/views/tabs/grid.cc +++ b/chrome/browser/views/tabs/grid.cc @@ -63,6 +63,21 @@ void Grid::AnimateToTargetBounds() { CalculateTargetBoundsAndStartAnimation(); } +int Grid::AnimationPosition(int start, int target) { + return start + static_cast<int>( + static_cast<double>(target - start) * animation_.GetCurrentValue()); +} + +gfx::Rect Grid::AnimationPosition(const gfx::Rect& start_bounds, + const gfx::Rect& target_bounds) { + return gfx::Rect(AnimationPosition(start_bounds.x(), target_bounds.x()), + AnimationPosition(start_bounds.y(), target_bounds.y()), + AnimationPosition(start_bounds.width(), + target_bounds.width()), + AnimationPosition(start_bounds.height(), + target_bounds.height())); +} + void Grid::ViewHierarchyChanged(bool is_add, View* parent, View* child) { if (modifying_children_ || parent != this) return; @@ -131,15 +146,8 @@ void Grid::AnimationProgressed(const Animation* animation) { 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( - gfx::Rect(AnimationPosition(start_bounds.x(), target_bounds.x()), - AnimationPosition(start_bounds.y(), target_bounds.y()), - AnimationPosition(start_bounds.width(), - target_bounds.width()), - AnimationPosition(start_bounds.height(), - target_bounds.height()))); - } + if (static_cast<int>(i) != floating_index_) + view->SetBounds(AnimationPosition(start_bounds, target_bounds)); } SchedulePaint(); } @@ -226,11 +234,9 @@ void Grid::CalculateTargetBoundsAndStartAnimation() { target_bounds_.clear(); CalculateCellBounds(&target_bounds_); - // And make sure the animation is running. - if (!animation_.IsAnimating()) { - animation_.Reset(); - animation_.Show(); - } + // And restart the animation. + animation_.Reset(); + animation_.Show(); } void Grid::SetViewBoundsToTarget() { @@ -240,8 +246,3 @@ void Grid::SetViewBoundsToTarget() { GetChildViewAt(i)->SetBounds(target_bounds_[i]); } } - -int Grid::AnimationPosition(int start, int target) { - return start + static_cast<int>( - static_cast<double>(target - start) * animation_.GetCurrentValue()); -} diff --git a/chrome/browser/views/tabs/grid.h b/chrome/browser/views/tabs/grid.h index ba86cbd..83653fb 100644 --- a/chrome/browser/views/tabs/grid.h +++ b/chrome/browser/views/tabs/grid.h @@ -65,6 +65,16 @@ class Grid : public views::View, public AnimationDelegate { // Returns the bounds of the specified cell. gfx::Rect CellBounds(int index); + // Returns the value based on the current animation. |start| gives the + // starting coordinate and |target| the target coordinate. The resulting + // value is between |start| and |target| based on the current animation. + int AnimationPosition(int start, int target); + + // Convenience for returning a rectangle between |start_bounds| and + // |target_bounds| based on the current animation. + gfx::Rect AnimationPosition(const gfx::Rect& start_bounds, + const gfx::Rect& target_bounds); + // View overrides. virtual void ViewHierarchyChanged(bool is_add, views::View* parent, @@ -94,11 +104,6 @@ class Grid : public views::View, public AnimationDelegate { // Resets the bounds of each cell to that of target_bounds_. void SetViewBoundsToTarget(); - // Returns the value based on the current animation. |start| gives the - // starting coordinate and |target| the target coordinate. The resulting - // value is between |start| and |target| based on the current animation. - int AnimationPosition(int start, int target); - // The animation. SlideAnimation animation_; diff --git a/chrome/browser/views/tabs/tab_overview_container.cc b/chrome/browser/views/tabs/tab_overview_container.cc index d565261..54b6bf2 100644 --- a/chrome/browser/views/tabs/tab_overview_container.cc +++ b/chrome/browser/views/tabs/tab_overview_container.cc @@ -34,11 +34,12 @@ void TabOverviewContainer::SetMaxSize(const gfx::Size& max_size) { max_size.height() - kVerticalPadding * 2 - kArrowHeight)); } -void TabOverviewContainer::UpdateWidgetShape(int width, int height) { +void TabOverviewContainer::UpdateWidgetShape(int horizontal_center, + int width, int height) { int bottom_y = height - kArrowHeight; int right_edge = width - 1; int center = width / 2; - // The points in alternating x,y pairs. + // The points, in alternating x,y pairs. int points[] = { kEdgeInset, 0, right_edge - kEdgeInset, 0, diff --git a/chrome/browser/views/tabs/tab_overview_container.h b/chrome/browser/views/tabs/tab_overview_container.h index 119fde4..f346192 100644 --- a/chrome/browser/views/tabs/tab_overview_container.h +++ b/chrome/browser/views/tabs/tab_overview_container.h @@ -21,8 +21,10 @@ class TabOverviewContainer : public views::View { // adjusting for our borders. void SetMaxSize(const gfx::Size& max_size); - // Updates the shape on the containing widget. - void UpdateWidgetShape(int width, int height); + // Updates the shape on the containing widget. |horizontal_center| gives the + // center of the window the parent window we're contained in is centered + // over. + void UpdateWidgetShape(int horizontal_center, int width, int height); // View overrides. virtual gfx::Size GetPreferredSize(); diff --git a/chrome/browser/views/tabs/tab_overview_controller.cc b/chrome/browser/views/tabs/tab_overview_controller.cc index 2fdecbc..711a2b0 100644 --- a/chrome/browser/views/tabs/tab_overview_controller.cc +++ b/chrome/browser/views/tabs/tab_overview_controller.cc @@ -10,13 +10,21 @@ #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_grid.h" +#include "chrome/browser/views/tabs/tab_overview_types.h" #include "chrome/browser/window_sizer.h" #include "views/fill_layout.h" #include "views/widget/root_view.h" #include "views/widget/widget_gtk.h" +// Horizontal padding from the edge of the monitor to the overview. static int kMonitorPadding = 20; -static int kInteriorPadding = 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) @@ -26,7 +34,10 @@ TabOverviewController::TabOverviewController( browser_(NULL), drag_browser_(NULL), moved_offscreen_(false), - shown_(false) { + shown_(false), + horizontal_center_(0), + change_window_bounds_on_animate_(false), + mutating_grid_(false) { grid_ = new TabOverviewGrid(this); // Create the host. @@ -34,6 +45,10 @@ TabOverviewController::TabOverviewController( host->set_delete_on_destroy(false); host->MakeTransparent(); host->Init(NULL, gfx::Rect(), true); + TabOverviewTypes::instance()->SetWindowType( + host->GetNativeView(), + TabOverviewTypes::WINDOW_TYPE_CHROME_TAB_SUMMARY, + NULL); host_ = host; container_ = new TabOverviewContainer(); @@ -41,15 +56,19 @@ TabOverviewController::TabOverviewController( host->GetRootView()->SetLayoutManager(new views::FillLayout()); host->GetRootView()->AddChildView(container_); - // Determine the bounds we're going to show at. + // 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)); - int max_width = monitor_bounds_.width() - kMonitorPadding * 2 - - kInteriorPadding * 2; - int max_height = monitor_bounds_.height() / 2; + monitor_bounds_.Inset(kMonitorPadding, 0); + int max_width = monitor_bounds_.width(); + int max_height = static_cast<int>(monitor_bounds_.height() * + kOverviewHeight); container_->SetMaxSize(gfx::Size(max_width, max_height)); + + // TODO: remove this when we get mid point. + horizontal_center_ = monitor_bounds_.x() + monitor_bounds_.width() / 2; } TabOverviewController::~TabOverviewController() { @@ -61,7 +80,10 @@ TabOverviewController::~TabOverviewController() { grid()->CancelDrag(); } -void TabOverviewController::SetBrowser(Browser* browser) { +void TabOverviewController::SetBrowser(Browser* browser, + int horizontal_center) { + // TODO: update this when we horizontal_center is correct. + // horizontal_center_ = horizontal_center; if (browser_) model()->RemoveObserver(this); browser_ = browser; @@ -122,6 +144,29 @@ void TabOverviewController::SelectTabContents(TabContents* contents) { NOTIMPLEMENTED(); } +void TabOverviewController::GridAnimationEnded() { + if (moved_offscreen_ || !change_window_bounds_on_animate_ || mutating_grid_) + return; + + SetHostBounds(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_); + + SetHostBounds(grid_->AnimationPosition(start_bounds_, target_bounds_)); + grid_->UpdateDragController(); +} + +void TabOverviewController::GridAnimationCanceled() { + change_window_bounds_on_animate_ = false; +} + void TabOverviewController::TabInsertedAt(TabContents* contents, int index, bool foreground) { @@ -130,9 +175,11 @@ void TabOverviewController::TabInsertedAt(TabContents* contents, TabOverviewCell* child = new TabOverviewCell(); ConfigureCell(child, index); + mutating_grid_ = true; grid_->InsertCell(index, child); + mutating_grid_ = false; - TabCountChanged(); + UpdateStartAndTargetBounds(); } void TabOverviewController::TabClosingAt(TabContents* contents, int index) { @@ -144,9 +191,11 @@ void TabOverviewController::TabDetachedAt(TabContents* contents, int index) { grid_->CancelDrag(); scoped_ptr<TabOverviewCell> child(grid_->GetTabOverviewCellAt(index)); + mutating_grid_ = true; grid_->RemoveCell(index); + mutating_grid_ = false; - TabCountChanged(); + UpdateStartAndTargetBounds(); } void TabOverviewController::TabMoved(TabContents* contents, @@ -155,7 +204,11 @@ void TabOverviewController::TabMoved(TabContents* contents, 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, @@ -185,19 +238,11 @@ void TabOverviewController::RecreateCells() { grid_->AddChildView(child); } } - TabCountChanged(); -} -void TabOverviewController::TabCountChanged() { if (moved_offscreen_) return; - gfx::Size pref = container_->GetPreferredSize(); - int x = monitor_bounds_.x() + (monitor_bounds_.width() - pref.width()) / 2; - int y = monitor_bounds_.y() + monitor_bounds_.height() / 2 - pref.height(); - host_->SetBounds(gfx::Rect(x, y, pref.width(), pref.height())); - - container_->UpdateWidgetShape(pref.width(), pref.height()); + SetHostBounds(CalculateHostBounds()); if (grid()->GetChildViewCount() > 0) { if (shown_) host_->Show(); @@ -205,3 +250,32 @@ void TabOverviewController::TabCountChanged() { host_->Hide(); } } + +void TabOverviewController::UpdateStartAndTargetBounds() { + if (moved_offscreen_ || !shown_) + return; + + if (grid()->GetChildViewCount() == 0) { + host_->Hide(); + } else { + host_->GetBounds(&start_bounds_, true); + target_bounds_ = CalculateHostBounds(); + change_window_bounds_on_animate_ = (start_bounds_ != target_bounds_); + } +} + +void TabOverviewController::SetHostBounds(const gfx::Rect& bounds) { + host_->SetBounds(bounds); + container_->UpdateWidgetShape(horizontal_center_, bounds.width(), + bounds.height()); +} + +gfx::Rect TabOverviewController::CalculateHostBounds() { + gfx::Size pref = container_->GetPreferredSize(); + int x = horizontal_center_ - pref.width() / 2; + int y = monitor_bounds_.bottom() - + static_cast<int>(monitor_bounds_.height() * kWindowHeight) - + kWindowToOverviewPadding - pref.height(); + return gfx::Rect(x, y, pref.width(), pref.height()). + AdjustToFit(monitor_bounds_); +} diff --git a/chrome/browser/views/tabs/tab_overview_controller.h b/chrome/browser/views/tabs/tab_overview_controller.h index 01600e2..50fac90 100644 --- a/chrome/browser/views/tabs/tab_overview_controller.h +++ b/chrome/browser/views/tabs/tab_overview_controller.h @@ -9,6 +9,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/tabs/tab_strip_model.h" +class Animation; class Browser; class TabOverviewCell; class TabOverviewContainer; @@ -27,8 +28,9 @@ class TabOverviewController : public TabStripModelObserver { explicit TabOverviewController(const gfx::Point& monitor_origin); ~TabOverviewController(); - // Sets the browser we're showing the tab strip for. - void SetBrowser(Browser* browser); + // 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; @@ -44,10 +46,15 @@ class TabOverviewController : public TabStripModelObserver { void ConfigureCell(TabOverviewCell* cell, TabContents* contents); // Invoked from TabOverviewDragController. - virtual void DragStarted(); - virtual void DragEnded(); - virtual void MoveOffscreen(); - virtual void SelectTabContents(TabContents* contents); + void DragStarted(); + void DragEnded(); + void MoveOffscreen(); + void SelectTabContents(TabContents* contents); + + // Forwarded from TabOverviewGrid as the animation of the grid changes. + void GridAnimationEnded(); + void GridAnimationProgressed(); + void GridAnimationCanceled(); // TabStripModelObserver overrides. virtual void TabInsertedAt(TabContents* contents, @@ -75,9 +82,14 @@ class TabOverviewController : public TabStripModelObserver { // Removes all the cells in the grid and populates it from the model. void RecreateCells(); - // Invoked when the count of the model changes. Notifies the host the pref - // size changed. - void TabCountChanged(); + // Updates the target and start bounds. + void UpdateStartAndTargetBounds(); + + // Sets the bounds of the hosting window to |bounds|. + void SetHostBounds(const gfx::Rect& bounds); + + // Returns the bounds for the window based on the current content. + gfx::Rect CalculateHostBounds(); // The widget showing the view. views::Widget* host_; @@ -104,6 +116,23 @@ class TabOverviewController : public TabStripModelObserver { // 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_; + DISALLOW_COPY_AND_ASSIGN(TabOverviewController); }; diff --git a/chrome/browser/views/tabs/tab_overview_drag_controller.cc b/chrome/browser/views/tabs/tab_overview_drag_controller.cc index 2427cdb..4245a45 100644 --- a/chrome/browser/views/tabs/tab_overview_drag_controller.cc +++ b/chrome/browser/views/tabs/tab_overview_drag_controller.cc @@ -9,9 +9,11 @@ #include "chrome/browser/dock_info.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" @@ -262,7 +264,7 @@ void TabOverviewDragController::DragCell(const gfx::Point& location) { } int new_index = std::min(model()->count() - 1, row * grid()->columns() + col); - if (detached_tab_ ) { + if (detached_tab_) { // The user dragged a detached tab back over the grid, reattach it. Attach(new_index); } else if (new_index != current_index_) { @@ -370,6 +372,17 @@ views::Widget* TabOverviewDragController::CreateDetachedWindow( widget->Init(NULL, gfx::Rect(screen_loc, cell->GetPreferredSize()), true); 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, + ¶ms); + return widget; } diff --git a/chrome/browser/views/tabs/tab_overview_grid.cc b/chrome/browser/views/tabs/tab_overview_grid.cc index e14da4a..faa151b 100644 --- a/chrome/browser/views/tabs/tab_overview_grid.cc +++ b/chrome/browser/views/tabs/tab_overview_grid.cc @@ -7,6 +7,7 @@ #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) { @@ -27,6 +28,14 @@ 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; @@ -61,3 +70,18 @@ void TabOverviewGrid::OnMouseReleased(const views::MouseEvent& event, 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 index bedf4ce..afb4aba 100644 --- a/chrome/browser/views/tabs/tab_overview_grid.h +++ b/chrome/browser/views/tabs/tab_overview_grid.h @@ -30,11 +30,20 @@ class TabOverviewGrid : public Grid { // 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_; diff --git a/chrome/browser/views/tabs/tab_overview_message_listener.cc b/chrome/browser/views/tabs/tab_overview_message_listener.cc new file mode 100644 index 0000000..8cced05 --- /dev/null +++ b/chrome/browser/views/tabs/tab_overview_message_listener.cc @@ -0,0 +1,76 @@ +// 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/gtk/browser_window_gtk.h" +#include "chrome/common/x11_util.h" +#include "chrome/browser/views/tabs/tab_overview_controller.h" + +// static +TabOverviewMessageListener* TabOverviewMessageListener::instance() { + static TabOverviewMessageListener* instance = NULL; + if (!instance) { + instance = Singleton<TabOverviewMessageListener>::get(); + MessageLoopForUI::current()->AddObserver(instance); + } + return instance; +} + +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); + if (TabOverviewTypes::instance()->DecodeMessage(*client_event, &message)) + ProcessMessage(message, client_event->window); + } +} + +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 { + BrowserWindowGtk* browser_window = + BrowserWindowGtk::GetBrowserWindowForNativeWindow( + BrowserWindowGtk::GetBrowserWindowForXID( + x11_util::GetX11WindowFromGdkWindow(window))); + if (browser_window) + ShowOverview(browser_window->browser()); + else + HideOverview(); + } + break; + } + default: + break; + } +} + +void TabOverviewMessageListener::ShowOverview(Browser* browser) { + if (!controller_.get()) { + controller_.reset(new TabOverviewController( + browser->window()->GetNormalBounds().origin())); + } + // TODO: get x-coordinate when available. + controller_->SetBrowser(browser, -1); + controller_->Show(); +} + +void TabOverviewMessageListener::HideOverview() { + controller_.reset(NULL); +} diff --git a/chrome/browser/views/tabs/tab_overview_message_listener.h b/chrome/browser/views/tabs/tab_overview_message_listener.h new file mode 100644 index 0000000..154dd6f --- /dev/null +++ b/chrome/browser/views/tabs/tab_overview_message_listener.h @@ -0,0 +1,52 @@ +// 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; +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>; + + 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); + + // Hids the tab overview. + void HideOverview(); + + // If non-null tab overview is showing. + scoped_ptr<TabOverviewController> controller_; + + DISALLOW_COPY_AND_ASSIGN(TabOverviewMessageListener); +}; + +#endif // CHROME_BROWSER_VIEWS_TABS_TAB_OVERVIEW_MESSAGE_LISTENER_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index a36f0a3..c091233 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1613,6 +1613,10 @@ 'browser/views/tabs/tab_overview_drag_controller.h', 'browser/views/tabs/tab_overview_grid.cc', 'browser/views/tabs/tab_overview_grid.h', + 'browser/views/tabs/tab_overview_message_listener.cc', + 'browser/views/tabs/tab_overview_message_listener.h', + 'browser/views/tabs/tab_overview_types.cc', + 'browser/views/tabs/tab_overview_types.h', 'browser/views/tabs/tab_renderer.cc', 'browser/views/tabs/tab_renderer.h', 'browser/views/tabs/tab_strip.cc', @@ -1796,6 +1800,10 @@ 'browser/views/tabs/tab_overview_drag_controller.h', 'browser/views/tabs/tab_overview_grid.cc', 'browser/views/tabs/tab_overview_grid.h', + 'browser/views/tabs/tab_overview_message_listener.cc', + 'browser/views/tabs/tab_overview_message_listener.h', + 'browser/views/tabs/tab_overview_types.cc', + 'browser/views/tabs/tab_overview_types.h', ], 'configurations': { 'Debug': { @@ -1931,6 +1939,10 @@ ['include', 'browser/views/tabs/tab_overview_drag_controller.h'], ['include', 'browser/views/tabs/tab_overview_grid.cc'], ['include', 'browser/views/tabs/tab_overview_grid.h'], + ['include', 'browser/views/tabs/tab_overview_message_listener.cc'], + ['include', 'browser/views/tabs/tab_overview_message_listener.h'], + ['include', 'browser/views/tabs/tab_overview_types.cc'], + ['include', 'browser/views/tabs/tab_overview_types.h'], ], }], ], diff --git a/views/screen_gtk.cc b/views/screen_gtk.cc index 964d580..efb8775 100644 --- a/views/screen_gtk.cc +++ b/views/screen_gtk.cc @@ -11,7 +11,7 @@ namespace views { // static gfx::Point Screen::GetCursorScreenPoint() { gint x, y; - gdk_display_get_pointer(NULL, NULL, &x, &y, NULL); + gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); return gfx::Point(x, y); } |