| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/tabs/dragged_tab_view.h" | 5 #include "chrome/browser/views/tabs/dragged_tab_view.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
| 9 #include "chrome/browser/tabs/tab_strip_model.h" | 9 #include "chrome/browser/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/views/tabs/native_view_photobooth.h" | 10 #include "chrome/browser/views/tabs/native_view_photobooth.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 container_->Init(NULL, gfx::Rect(0, 0, 0, 0)); | 54 container_->Init(NULL, gfx::Rect(0, 0, 0, 0)); |
| 55 container_->SetContentsView(this); | 55 container_->SetContentsView(this); |
| 56 | 56 |
| 57 BOOL drag; | 57 BOOL drag; |
| 58 if ((::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, &drag, 0) != 0) && | 58 if ((::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, &drag, 0) != 0) && |
| 59 (drag == FALSE)) { | 59 (drag == FALSE)) { |
| 60 show_contents_on_drag_ = false; | 60 show_contents_on_drag_ = false; |
| 61 } | 61 } |
| 62 #else | 62 #else |
| 63 container_.reset(new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP)); | 63 container_.reset(new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP)); |
| 64 container_->MakeTransparent(); |
| 64 container_->set_delete_on_destroy(false); | 65 container_->set_delete_on_destroy(false); |
| 65 container_->Init(NULL, gfx::Rect(0, 0, 0, 0)); | 66 container_->Init(NULL, gfx::Rect(0, 0, 0, 0)); |
| 66 container_->SetContentsView(this); | 67 container_->SetContentsView(this); |
| 67 #endif | 68 #endif |
| 68 } | 69 } |
| 69 | 70 |
| 70 DraggedTabView::~DraggedTabView() { | 71 DraggedTabView::~DraggedTabView() { |
| 71 if (close_animation_.IsAnimating()) | 72 if (close_animation_.IsAnimating()) |
| 72 close_animation_.Stop(); | 73 close_animation_.Stop(); |
| 73 GetParent()->RemoveChildView(this); | 74 GetParent()->RemoveChildView(this); |
| 74 #if defined(OS_WIN) | |
| 75 container_->CloseNow(); | 75 container_->CloseNow(); |
| 76 #else | |
| 77 NOTIMPLEMENTED(); | |
| 78 #endif | |
| 79 } | 76 } |
| 80 | 77 |
| 81 void DraggedTabView::MoveTo(const gfx::Point& screen_point) { | 78 void DraggedTabView::MoveTo(const gfx::Point& screen_point) { |
| 82 #if defined(OS_WIN) | |
| 83 int show_flags = container_->IsVisible() ? SWP_NOZORDER : SWP_SHOWWINDOW; | |
| 84 | |
| 85 int x; | 79 int x; |
| 86 if (UILayoutIsRightToLeft() && !attached_) { | 80 if (UILayoutIsRightToLeft() && !attached_) { |
| 87 // On RTL locales, a dragged tab (when it is not attached to a tab strip) | 81 // On RTL locales, a dragged tab (when it is not attached to a tab strip) |
| 88 // is rendered using a right-to-left orientation so we should calculate the | 82 // is rendered using a right-to-left orientation so we should calculate the |
| 89 // window position differently. | 83 // window position differently. |
| 90 gfx::Size ps = GetPreferredSize(); | 84 gfx::Size ps = GetPreferredSize(); |
| 91 x = screen_point.x() - ScaleValue(ps.width()) + mouse_tab_offset_.x() + | 85 x = screen_point.x() - ScaleValue(ps.width()) + mouse_tab_offset_.x() + |
| 92 ScaleValue( | 86 ScaleValue( |
| 93 renderer_->MirroredXCoordinateInsideView(mouse_tab_offset_.x())); | 87 renderer_->MirroredXCoordinateInsideView(mouse_tab_offset_.x())); |
| 94 } else { | 88 } else { |
| 95 x = screen_point.x() + mouse_tab_offset_.x() - | 89 x = screen_point.x() + mouse_tab_offset_.x() - |
| 96 ScaleValue(mouse_tab_offset_.x()); | 90 ScaleValue(mouse_tab_offset_.x()); |
| 97 } | 91 } |
| 98 int y = screen_point.y() + mouse_tab_offset_.y() - | 92 int y = screen_point.y() + mouse_tab_offset_.y() - |
| 99 ScaleValue(mouse_tab_offset_.y()); | 93 ScaleValue(mouse_tab_offset_.y()); |
| 100 | 94 |
| 95 #if defined(OS_WIN) |
| 96 int show_flags = container_->IsVisible() ? SWP_NOZORDER : SWP_SHOWWINDOW; |
| 97 |
| 101 container_->SetWindowPos(HWND_TOP, x, y, 0, 0, | 98 container_->SetWindowPos(HWND_TOP, x, y, 0, 0, |
| 102 SWP_NOSIZE | SWP_NOACTIVATE | show_flags); | 99 SWP_NOSIZE | SWP_NOACTIVATE | show_flags); |
| 103 #else | 100 #else |
| 104 NOTIMPLEMENTED(); | 101 gfx::Rect bounds; |
| 102 container_->GetBounds(&bounds, true); |
| 103 container_->SetBounds(gfx::Rect(x, y, bounds.width(), bounds.height())); |
| 104 if (!container_->IsVisible()) |
| 105 container_->Show(); |
| 105 #endif | 106 #endif |
| 106 } | 107 } |
| 107 | 108 |
| 108 void DraggedTabView::Attach(int selected_width) { | 109 void DraggedTabView::Attach(int selected_width) { |
| 109 attached_ = true; | 110 attached_ = true; |
| 110 photobooth_ = NULL; | 111 photobooth_ = NULL; |
| 111 #if defined(OS_WIN) | 112 #if defined(OS_WIN) |
| 112 container_->SetOpacity(kOpaqueAlpha); | 113 container_->SetOpacity(kOpaqueAlpha); |
| 113 #else | |
| 114 NOTIMPLEMENTED(); | |
| 115 #endif | 114 #endif |
| 116 Resize(selected_width); | 115 Resize(selected_width); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void DraggedTabView::Resize(int width) { | 118 void DraggedTabView::Resize(int width) { |
| 120 attached_tab_size_.set_width(width); | 119 attached_tab_size_.set_width(width); |
| 121 ResizeContainer(); | 120 ResizeContainer(); |
| 122 Update(); | 121 Update(); |
| 123 } | 122 } |
| 124 | 123 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 | 135 |
| 137 if (attached_tab_size_.width() != tab_width_) { | 136 if (attached_tab_size_.width() != tab_width_) { |
| 138 // The attached tab size differs from current tab size. Resize accordingly. | 137 // The attached tab size differs from current tab size. Resize accordingly. |
| 139 Resize(tab_width_); | 138 Resize(tab_width_); |
| 140 } | 139 } |
| 141 | 140 |
| 142 attached_ = false; | 141 attached_ = false; |
| 143 photobooth_ = photobooth; | 142 photobooth_ = photobooth; |
| 144 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
| 145 container_->SetOpacity(kTransparentAlpha); | 144 container_->SetOpacity(kTransparentAlpha); |
| 146 #else | |
| 147 NOTIMPLEMENTED(); | |
| 148 #endif | 145 #endif |
| 149 ResizeContainer(); | 146 ResizeContainer(); |
| 150 Update(); | 147 Update(); |
| 151 } | 148 } |
| 152 | 149 |
| 153 void DraggedTabView::Update() { | 150 void DraggedTabView::Update() { |
| 154 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
| 155 container_->set_can_update_layered_window(true); | 152 container_->set_can_update_layered_window(true); |
| 156 SchedulePaint(); | 153 SchedulePaint(); |
| 157 container_->PaintNow(gfx::Rect()); | 154 container_->PaintNow(gfx::Rect()); |
| 158 container_->set_can_update_layered_window(false); | 155 container_->set_can_update_layered_window(false); |
| 159 #else | 156 #else |
| 160 NOTIMPLEMENTED(); | 157 SchedulePaint(); |
| 161 #endif | 158 #endif |
| 162 } | 159 } |
| 163 | 160 |
| 164 void DraggedTabView::AnimateToBounds(const gfx::Rect& bounds, | 161 void DraggedTabView::AnimateToBounds(const gfx::Rect& bounds, |
| 165 Callback0::Type* callback) { | 162 Callback0::Type* callback) { |
| 166 animation_callback_.reset(callback); | 163 animation_callback_.reset(callback); |
| 167 | 164 |
| 168 gfx::Rect initial_bounds; | 165 gfx::Rect initial_bounds; |
| 169 GetWidget()->GetBounds(&initial_bounds, true); | 166 GetWidget()->GetBounds(&initial_bounds, true); |
| 170 animation_start_bounds_ = initial_bounds; | 167 animation_start_bounds_ = initial_bounds; |
| 171 animation_end_bounds_ = bounds; | 168 animation_end_bounds_ = bounds; |
| 172 | 169 |
| 173 close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs); | 170 close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs); |
| 174 close_animation_.SetTweenType(SlideAnimation::EASE_OUT); | 171 close_animation_.SetTweenType(SlideAnimation::EASE_OUT); |
| 175 if (!close_animation_.IsShowing()) { | 172 if (!close_animation_.IsShowing()) { |
| 176 close_animation_.Reset(); | 173 close_animation_.Reset(); |
| 177 close_animation_.Show(); | 174 close_animation_.Show(); |
| 178 } | 175 } |
| 179 } | 176 } |
| 180 | 177 |
| 181 /////////////////////////////////////////////////////////////////////////////// | 178 /////////////////////////////////////////////////////////////////////////////// |
| 182 // DraggedTabView, AnimationDelegate implementation: | 179 // DraggedTabView, AnimationDelegate implementation: |
| 183 | 180 |
| 184 void DraggedTabView::AnimationProgressed(const Animation* animation) { | 181 void DraggedTabView::AnimationProgressed(const Animation* animation) { |
| 185 #if defined(OS_WIN) | |
| 186 int delta_x = (animation_end_bounds_.x() - animation_start_bounds_.x()); | 182 int delta_x = (animation_end_bounds_.x() - animation_start_bounds_.x()); |
| 187 int x = animation_start_bounds_.x() + | 183 int x = animation_start_bounds_.x() + |
| 188 static_cast<int>(delta_x * animation->GetCurrentValue()); | 184 static_cast<int>(delta_x * animation->GetCurrentValue()); |
| 189 int y = animation_end_bounds_.y(); | 185 int y = animation_end_bounds_.y(); |
| 186 #if defined(OS_WIN) |
| 190 container_->SetWindowPos(NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE); | 187 container_->SetWindowPos(NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE); |
| 191 #else | 188 #else |
| 189 gfx::Rect bounds; |
| 190 container_->GetBounds(&bounds, true); |
| 191 container_->SetBounds(gfx::Rect(x, y, bounds.width(), bounds.height())); |
| 192 #endif | 192 #endif |
| 193 } | 193 } |
| 194 | 194 |
| 195 void DraggedTabView::AnimationEnded(const Animation* animation) { | 195 void DraggedTabView::AnimationEnded(const Animation* animation) { |
| 196 animation_callback_->Run(); | 196 animation_callback_->Run(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void DraggedTabView::AnimationCanceled(const Animation* animation) { | 199 void DraggedTabView::AnimationCanceled(const Animation* animation) { |
| 200 AnimationEnded(animation); | 200 AnimationEnded(animation); |
| 201 } | 201 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 void DraggedTabView::PaintFocusRect(gfx::Canvas* canvas) { | 299 void DraggedTabView::PaintFocusRect(gfx::Canvas* canvas) { |
| 300 gfx::Size ps = GetPreferredSize(); | 300 gfx::Size ps = GetPreferredSize(); |
| 301 canvas->DrawFocusRect(0, 0, | 301 canvas->DrawFocusRect(0, 0, |
| 302 static_cast<int>(ps.width() * kScalingFactor), | 302 static_cast<int>(ps.width() * kScalingFactor), |
| 303 static_cast<int>(ps.height() * kScalingFactor)); | 303 static_cast<int>(ps.height() * kScalingFactor)); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void DraggedTabView::ResizeContainer() { | 306 void DraggedTabView::ResizeContainer() { |
| 307 gfx::Size ps = GetPreferredSize(); | 307 gfx::Size ps = GetPreferredSize(); |
| 308 int w = ScaleValue(ps.width()); |
| 309 int h = ScaleValue(ps.height()); |
| 308 #if defined(OS_WIN) | 310 #if defined(OS_WIN) |
| 309 SetWindowPos(container_->GetNativeView(), HWND_TOPMOST, 0, 0, | 311 SetWindowPos(container_->GetNativeView(), HWND_TOPMOST, 0, 0, w, h, |
| 310 ScaleValue(ps.width()), ScaleValue(ps.height()), | |
| 311 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); | 312 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); |
| 312 #else | 313 #else |
| 313 NOTIMPLEMENTED(); | 314 gfx::Rect bounds; |
| 315 container_->GetBounds(&bounds, true); |
| 316 container_->SetBounds(gfx::Rect(bounds.x(), bounds.y(), w, h)); |
| 314 #endif | 317 #endif |
| 315 } | 318 } |
| 316 | 319 |
| 317 int DraggedTabView::ScaleValue(int value) { | 320 int DraggedTabView::ScaleValue(int value) { |
| 318 return attached_ ? value : static_cast<int>(value * kScalingFactor); | 321 return attached_ ? value : static_cast<int>(value * kScalingFactor); |
| 319 } | 322 } |
| OLD | NEW |