| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" | 5 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
| 9 #include "chrome/browser/ui/panels/panel.h" | 9 #include "chrome/browser/ui/panels/panel.h" |
| 10 #include "chrome/browser/ui/panels/panel_manager.h" | 10 #include "chrome/browser/ui/panels/panel_manager.h" |
| 11 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 11 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
| 12 #include "chrome/browser/ui/panels/panel_slide_animation.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 14 #include "ui/base/animation/slide_animation.h" | 15 #include "ui/base/animation/slide_animation.h" |
| 15 #include "ui/base/dragdrop/gtk_dnd_util.h" | 16 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 16 #include "ui/base/x/work_area_watcher_x.h" | 17 #include "ui/base/x/work_area_watcher_x.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // This value is experimental and subjective. | |
| 21 const int kSetBoundsAnimationMs = 180; | |
| 22 | |
| 23 // RGB values for titlebar in draw attention state. A shade of orange. | 21 // RGB values for titlebar in draw attention state. A shade of orange. |
| 24 const int kDrawAttentionR = 0xfa; | 22 const int kDrawAttentionR = 0xfa; |
| 25 const int kDrawAttentionG = 0x98; | 23 const int kDrawAttentionG = 0x98; |
| 26 const int kDrawAttentionB = 0x3a; | 24 const int kDrawAttentionB = 0x3a; |
| 27 const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; | 25 const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; |
| 28 const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; | 26 const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; |
| 29 const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; | 27 const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; |
| 30 | 28 |
| 31 // Delay before click on a titlebar is allowed to minimize the panel after | 29 // Delay before click on a titlebar is allowed to minimize the panel after |
| 32 // the 'draw attention' mode has been cleared. | 30 // the 'draw attention' mode has been cleared. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 BrowserWindowGtk::OnSizeChanged(width, height); | 140 BrowserWindowGtk::OnSizeChanged(width, height); |
| 143 | 141 |
| 144 if (window_size_known_) | 142 if (window_size_known_) |
| 145 return; | 143 return; |
| 146 | 144 |
| 147 window_size_known_ = true; | 145 window_size_known_ = true; |
| 148 int top = bounds_.bottom() - height; | 146 int top = bounds_.bottom() - height; |
| 149 int left = bounds_.right() - width; | 147 int left = bounds_.right() - width; |
| 150 | 148 |
| 151 gtk_window_move(window_, left, top); | 149 gtk_window_move(window_, left, top); |
| 152 StartBoundsAnimation(gfx::Rect(left, top, width, height)); | 150 StartBoundsAnimation(bounds_, gfx::Rect(left, top, width, height)); |
| 153 panel_->OnWindowSizeAvailable(); | 151 panel_->OnWindowSizeAvailable(); |
| 154 | 152 |
| 155 content::NotificationService::current()->Notify( | 153 content::NotificationService::current()->Notify( |
| 156 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, | 154 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, |
| 157 content::Source<Panel>(panel_.get()), | 155 content::Source<Panel>(panel_.get()), |
| 158 content::NotificationService::NoDetails()); | 156 content::NotificationService::NoDetails()); |
| 159 } | 157 } |
| 160 | 158 |
| 161 bool PanelBrowserWindowGtk::UseCustomFrame() { | 159 bool PanelBrowserWindowGtk::UseCustomFrame() { |
| 162 // We always use custom frame for panels. | 160 // We always use custom frame for panels. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 bool animate) { | 253 bool animate) { |
| 256 if (bounds == bounds_) | 254 if (bounds == bounds_) |
| 257 return; | 255 return; |
| 258 | 256 |
| 259 if (drag_widget_ || !animate) { | 257 if (drag_widget_ || !animate) { |
| 260 DCHECK(!bounds_animator_.get() || !bounds_animator_->is_animating()); | 258 DCHECK(!bounds_animator_.get() || !bounds_animator_->is_animating()); |
| 261 // If the current panel is being dragged, it should just move with the | 259 // If the current panel is being dragged, it should just move with the |
| 262 // user drag, we should not animate. | 260 // user drag, we should not animate. |
| 263 gtk_window_move(window(), bounds.x(), bounds.y()); | 261 gtk_window_move(window(), bounds.x(), bounds.y()); |
| 264 } else if (window_size_known_) { | 262 } else if (window_size_known_) { |
| 265 StartBoundsAnimation(bounds_); | 263 StartBoundsAnimation(bounds_, bounds); |
| 266 } | 264 } |
| 267 // If window size is not known, wait till the size is known before starting | 265 // If window size is not known, wait till the size is known before starting |
| 268 // the animation. | 266 // the animation. |
| 269 | 267 |
| 270 bounds_ = bounds; | 268 bounds_ = bounds; |
| 271 } | 269 } |
| 272 | 270 |
| 273 void PanelBrowserWindowGtk::ClosePanel() { | 271 void PanelBrowserWindowGtk::ClosePanel() { |
| 274 // Cancel any currently running animation since we're closing down. | 272 // Cancel any currently running animation since we're closing down. |
| 275 if (bounds_animator_.get()) | 273 if (bounds_animator_.get()) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 gfx::Size frame = GetNonClientFrameSize(); | 403 gfx::Size frame = GetNonClientFrameSize(); |
| 406 return gfx::Size(window_size.width() - frame.width(), | 404 return gfx::Size(window_size.width() - frame.width(), |
| 407 window_size.height() - frame.height()); | 405 window_size.height() - frame.height()); |
| 408 } | 406 } |
| 409 | 407 |
| 410 int PanelBrowserWindowGtk::TitleOnlyHeight() const { | 408 int PanelBrowserWindowGtk::TitleOnlyHeight() const { |
| 411 return titlebar_widget()->allocation.height; | 409 return titlebar_widget()->allocation.height; |
| 412 } | 410 } |
| 413 | 411 |
| 414 void PanelBrowserWindowGtk::StartBoundsAnimation( | 412 void PanelBrowserWindowGtk::StartBoundsAnimation( |
| 415 const gfx::Rect& current_bounds) { | 413 const gfx::Rect& from_bounds, const gfx::Rect& to_bounds) { |
| 416 animation_start_bounds_ = current_bounds; | 414 animation_start_bounds_ = from_bounds; |
| 417 | 415 |
| 418 if (!bounds_animator_.get()) { | 416 bounds_animator_.reset(new PanelSlideAnimation( |
| 419 bounds_animator_.reset(new ui::SlideAnimation(this)); | 417 this, panel_.get(), from_bounds, to_bounds)); |
| 420 bounds_animator_->SetSlideDuration(kSetBoundsAnimationMs); | |
| 421 } | |
| 422 | |
| 423 if (bounds_animator_->IsShowing()) | |
| 424 bounds_animator_->Reset(); | |
| 425 bounds_animator_->Show(); | 418 bounds_animator_->Show(); |
| 426 } | 419 } |
| 427 | 420 |
| 428 bool PanelBrowserWindowGtk::IsAnimatingBounds() const { | 421 bool PanelBrowserWindowGtk::IsAnimatingBounds() const { |
| 429 return bounds_animator_.get() && bounds_animator_->is_animating(); | 422 return bounds_animator_.get() && bounds_animator_->is_animating(); |
| 430 } | 423 } |
| 431 | 424 |
| 432 void PanelBrowserWindowGtk::WillProcessEvent(GdkEvent* event) { | 425 void PanelBrowserWindowGtk::WillProcessEvent(GdkEvent* event) { |
| 433 // Nothing to do. | 426 // Nothing to do. |
| 434 } | 427 } |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 } | 750 } |
| 758 } | 751 } |
| 759 | 752 |
| 760 bool NativePanelTestingGtk::IsWindowSizeKnown() const { | 753 bool NativePanelTestingGtk::IsWindowSizeKnown() const { |
| 761 return panel_browser_window_gtk_->window_size_known_; | 754 return panel_browser_window_gtk_->window_size_known_; |
| 762 } | 755 } |
| 763 | 756 |
| 764 bool NativePanelTestingGtk::IsAnimatingBounds() const { | 757 bool NativePanelTestingGtk::IsAnimatingBounds() const { |
| 765 return panel_browser_window_gtk_->IsAnimatingBounds(); | 758 return panel_browser_window_gtk_->IsAnimatingBounds(); |
| 766 } | 759 } |
| OLD | NEW |