Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/views/tabs/dragged_tab_controller.cc

Issue 42041: Changes docking in the following ways:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dock_info.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <math.h> 5 #include <math.h>
6 #include <set> 6 #include <set>
7 7
8 #include "chrome/browser/views/tabs/dragged_tab_controller.h" 8 #include "chrome/browser/views/tabs/dragged_tab_controller.h"
9 9
10 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
11 #include "chrome/browser/tab_contents/tab_contents.h" 11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/browser/metrics/user_metrics.h" 12 #include "chrome/browser/metrics/user_metrics.h"
13 #include "chrome/browser/views/frame/browser_view.h" 13 #include "chrome/browser/views/frame/browser_view.h"
14 #include "chrome/browser/views/tabs/dragged_tab_view.h" 14 #include "chrome/browser/views/tabs/dragged_tab_view.h"
15 #include "chrome/browser/views/tabs/hwnd_photobooth.h" 15 #include "chrome/browser/views/tabs/hwnd_photobooth.h"
16 #include "chrome/browser/views/tabs/tab.h" 16 #include "chrome/browser/views/tabs/tab.h"
17 #include "chrome/browser/views/tabs/tab_strip.h" 17 #include "chrome/browser/views/tabs/tab_strip.h"
18 #include "chrome/browser/tab_contents/web_contents.h" 18 #include "chrome/browser/tab_contents/web_contents.h"
19 #include "chrome/common/animation.h" 19 #include "chrome/common/animation.h"
20 #include "chrome/common/gfx/chrome_canvas.h" 20 #include "chrome/common/gfx/chrome_canvas.h"
21 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
22 #include "chrome/common/resource_bundle.h"
22 #include "chrome/views/event.h" 23 #include "chrome/views/event.h"
23 #include "chrome/views/root_view.h" 24 #include "chrome/views/root_view.h"
25 #include "grit/theme_resources.h"
24 #include "skia/include/SkBitmap.h" 26 #include "skia/include/SkBitmap.h"
25 27
26 static const int kHorizontalMoveThreshold = 16; // pixels 28 static const int kHorizontalMoveThreshold = 16; // pixels
27 29
28 namespace { 30 namespace {
29 31
30 // Horizontal width of DockView. The height is 3/4 of this. If you change this,
31 // be sure and update the constants in DockInfo (kEnableDeltaX/kEnableDeltaY).
32 const int kDropWindowSize = 100;
33
34 // Delay, in ms, during dragging before we bring a window to front. 32 // Delay, in ms, during dragging before we bring a window to front.
35 const int kBringToFrontDelay = 750; 33 const int kBringToFrontDelay = 750;
36 34
37 // TODO (glen): nuke this class in favor of something pretty. Consider this 35 // Radius of the rect drawn by DockView.
38 // class a placeholder for the real thing. 36 const int kRoundedRectRadius = 4;
37
38 // Spacing between tab icons when DockView is showing a docking location that
39 // contains more than one tab.
40 const int kTabSpacing = 4;
41
42 // DockView is the view responsible for giving a visual indicator of where a
43 // dock is going to occur.
44
39 class DockView : public views::View { 45 class DockView : public views::View {
40 public: 46 public:
41 explicit DockView(DockInfo::Type type) 47 explicit DockView(DockInfo::Type type) : type_(type) {}
42 : size_(kDropWindowSize),
43 rect_radius_(4),
44 stroke_size_(4),
45 inner_stroke_size_(2),
46 inner_margin_(8),
47 inner_padding_(8),
48 type_(type) {}
49 48
50 virtual gfx::Size GetPreferredSize() { 49 virtual gfx::Size GetPreferredSize() {
51 return gfx::Size(size_, size_); 50 return gfx::Size(DockInfo::popup_width(), DockInfo::popup_height());
52 } 51 }
53 52
54 virtual void PaintBackground(ChromeCanvas* canvas) { 53 virtual void PaintBackground(ChromeCanvas* canvas) {
55 int h = size_ * 3 / 4; 54 SkRect outer_rect = { SkIntToScalar(0), SkIntToScalar(0),
56 int outer_x = (width() - size_) / 2; 55 SkIntToScalar(width()),
57 int outer_y = (height() - h) / 2; 56 SkIntToScalar(height()) };
58 switch (type_) {
59 case DockInfo::MAXIMIZE:
60 outer_y = 0;
61 break;
62 case DockInfo::LEFT_HALF:
63 outer_x = 0;
64 break;
65 case DockInfo::RIGHT_HALF:
66 outer_x = width() - size_;
67 break;
68 case DockInfo::BOTTOM_HALF:
69 outer_y = height() - h;
70 break;
71 default:
72 break;
73 }
74
75 SkRect outer_rect = { SkIntToScalar(outer_x),
76 SkIntToScalar(outer_y),
77 SkIntToScalar(outer_x + size_),
78 SkIntToScalar(outer_y + h) };
79 57
80 // Fill the background rect. 58 // Fill the background rect.
81 SkPaint paint; 59 SkPaint paint;
82 paint.setColor(SkColorSetRGB(58, 58, 58)); 60 paint.setColor(SkColorSetRGB(108, 108, 108));
83 paint.setStyle(SkPaint::kFill_Style); 61 paint.setStyle(SkPaint::kFill_Style);
84 canvas->drawRoundRect(outer_rect, SkIntToScalar(rect_radius_), 62 canvas->drawRoundRect(outer_rect, SkIntToScalar(kRoundedRectRadius),
85 SkIntToScalar(rect_radius_), paint); 63 SkIntToScalar(kRoundedRectRadius), paint);
86 64
87 // Outline the background rect. 65 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
88 paint.setFlags(SkPaint::kAntiAlias_Flag);
89 paint.setStrokeWidth(SkIntToScalar(stroke_size_));
90 paint.setColor(SK_ColorBLACK);
91 paint.setStyle(SkPaint::kStroke_Style);
92 canvas->drawRoundRect(outer_rect, SkIntToScalar(rect_radius_),
93 SkIntToScalar(rect_radius_), paint);
94 66
95 // Then the inner rect. 67 SkBitmap* high_icon = rb.GetBitmapNamed(IDR_DOCK_HIGH);
96 int inner_x = outer_x + inner_margin_; 68 SkBitmap* wide_icon = rb.GetBitmapNamed(IDR_DOCK_WIDE);
97 int inner_y = outer_y + inner_margin_; 69
98 int inner_width =
99 (size_ - inner_margin_ - inner_margin_ - inner_padding_) / 2;
100 int inner_height = (h - inner_margin_ - inner_margin_);
101 switch (type_) { 70 switch (type_) {
102 case DockInfo::LEFT_OF_WINDOW: 71 case DockInfo::LEFT_OF_WINDOW:
72 case DockInfo::LEFT_HALF:
73 canvas->DrawBitmapInt(*high_icon,
74 width() / 2 - high_icon->width() - kTabSpacing / 2,
75 (height() - high_icon->height()) / 2);
76 if (type_ == DockInfo::LEFT_OF_WINDOW) {
77 DrawBitmapWithAlpha(canvas, *high_icon, width() / 2 + kTabSpacing / 2,
78 (height() - high_icon->height()) / 2);
79 }
80 break;
81
82
103 case DockInfo::RIGHT_OF_WINDOW: 83 case DockInfo::RIGHT_OF_WINDOW:
104 DrawWindow(canvas, inner_x, inner_y, inner_width, inner_height); 84 case DockInfo::RIGHT_HALF:
105 DrawWindow(canvas, inner_x + inner_width + inner_padding_, inner_y, 85 canvas->DrawBitmapInt(*high_icon, width() / 2 + kTabSpacing / 2,
106 inner_width, inner_height); 86 (height() - high_icon->height()) / 2);
87 if (type_ == DockInfo::RIGHT_OF_WINDOW) {
88 DrawBitmapWithAlpha(canvas, *high_icon,
89 width() / 2 - high_icon->width() - kTabSpacing / 2,
90 (height() - high_icon->height()) / 2);
91 }
107 break; 92 break;
108 93
109 case DockInfo::TOP_OF_WINDOW: 94 case DockInfo::TOP_OF_WINDOW:
110 case DockInfo::BOTTOM_OF_WINDOW: 95 canvas->DrawBitmapInt(*wide_icon, (width() - wide_icon->width()) / 2,
111 inner_height = 96 height() / 2 - high_icon->height());
112 (h - inner_margin_ - inner_margin_ - inner_padding_) / 2;
113 inner_width += inner_width + inner_padding_;
114 DrawWindow(canvas, inner_x, inner_y, inner_width, inner_height);
115 DrawWindow(canvas, inner_x, inner_y + inner_height + inner_padding_,
116 inner_width, inner_height);
117 break; 97 break;
118 98
119 case DockInfo::MAXIMIZE: 99 case DockInfo::MAXIMIZE: {
120 inner_width += inner_width + inner_padding_; 100 SkBitmap* max_icon = rb.GetBitmapNamed(IDR_DOCK_MAX);
121 DrawWindow(canvas, inner_x, inner_y, inner_width, inner_height); 101 canvas->DrawBitmapInt(*max_icon, (width() - max_icon->width()) / 2,
102 (height() - max_icon->height()) / 2);
122 break; 103 break;
123 104 }
124 case DockInfo::LEFT_HALF:
125 DrawWindow(canvas, inner_x, inner_y, inner_width, inner_height);
126 break;
127
128 case DockInfo::RIGHT_HALF:
129 DrawWindow(canvas, inner_x + inner_width + inner_padding_, inner_y,
130 inner_width, inner_height);
131 break;
132 105
133 case DockInfo::BOTTOM_HALF: 106 case DockInfo::BOTTOM_HALF:
134 inner_height = 107 case DockInfo::BOTTOM_OF_WINDOW:
135 (h - inner_margin_ - inner_margin_ - inner_padding_) / 2; 108 canvas->DrawBitmapInt(*wide_icon, (width() - wide_icon->width()) / 2,
136 inner_width += inner_width + inner_padding_; 109 height() / 2 + kTabSpacing / 2);
137 DrawWindow(canvas, inner_x, inner_y + inner_height + inner_padding_, 110 if (type_ == DockInfo::BOTTOM_OF_WINDOW) {
138 inner_width, inner_height); 111 DrawBitmapWithAlpha(canvas, *wide_icon,
112 (width() - wide_icon->width()) / 2,
113 height() / 2 - kTabSpacing / 2 - wide_icon->height());
114 }
139 break; 115 break;
140 } 116 }
141 } 117 }
142 118
143 private: 119 private:
144 void DrawWindow(ChromeCanvas* canvas, int x, int y, int w, int h) { 120 void DrawBitmapWithAlpha(ChromeCanvas* canvas, const SkBitmap& image,
145 canvas->FillRectInt(SkColorSetRGB(160, 160, 160), x, y, w, h); 121 int x, int y) {
146
147 SkPaint paint; 122 SkPaint paint;
148 paint.setStrokeWidth(SkIntToScalar(inner_stroke_size_)); 123 paint.setAlpha(128);
149 paint.setColor(SK_ColorWHITE); 124 canvas->DrawBitmapInt(image, x, y, paint);
150 paint.setStyle(SkPaint::kStroke_Style);
151 SkRect rect = { SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w),
152 SkIntToScalar(y + h) };
153 canvas->drawRect(rect, paint);
154 } 125 }
155 126
156 int size_;
157 int rect_radius_;
158 int stroke_size_;
159 int inner_stroke_size_;
160 int inner_margin_;
161 int inner_padding_;
162 DockInfo::Type type_; 127 DockInfo::Type type_;
163 128
164 DISALLOW_COPY_AND_ASSIGN(DockView); 129 DISALLOW_COPY_AND_ASSIGN(DockView);
165 }; 130 };
166 131
167 gfx::Point ConvertScreenPointToTabStripPoint(TabStrip* tabstrip, 132 gfx::Point ConvertScreenPointToTabStripPoint(TabStrip* tabstrip,
168 const gfx::Point& screen_point) { 133 const gfx::Point& screen_point) {
169 gfx::Point tabstrip_topleft; 134 gfx::Point tabstrip_topleft;
170 views::View::ConvertPointToScreen(tabstrip, &tabstrip_topleft); 135 views::View::ConvertPointToScreen(tabstrip, &tabstrip_topleft);
171 return gfx::Point(screen_point.x() - tabstrip_topleft.x(), 136 return gfx::Point(screen_point.x() - tabstrip_topleft.x(),
(...skipping 10 matching lines...) Expand all
182 // a window with a DockView in it. Two animations are used that correspond to 147 // a window with a DockView in it. Two animations are used that correspond to
183 // the state of DockInfo::in_enable_area. 148 // the state of DockInfo::in_enable_area.
184 class DraggedTabController::DockDisplayer : public AnimationDelegate { 149 class DraggedTabController::DockDisplayer : public AnimationDelegate {
185 public: 150 public:
186 DockDisplayer(DraggedTabController* controller, 151 DockDisplayer(DraggedTabController* controller,
187 const DockInfo& info) 152 const DockInfo& info)
188 : controller_(controller), 153 : controller_(controller),
189 popup_(NULL), 154 popup_(NULL),
190 popup_hwnd_(NULL), 155 popup_hwnd_(NULL),
191 #pragma warning(suppress: 4355) // Okay to pass "this" here. 156 #pragma warning(suppress: 4355) // Okay to pass "this" here.
192 hot_animation_(this), 157 animation_(this),
193 enable_animation_(this),
194 hidden_(false), 158 hidden_(false),
195 in_enable_area_(info.in_enable_area()) { 159 in_enable_area_(info.in_enable_area()) {
196 gfx::Rect bounds(info.hot_spot().x() - kDropWindowSize / 2,
197 info.hot_spot().y() - kDropWindowSize / 2,
198 kDropWindowSize, kDropWindowSize);
199 switch (info.type()) {
200 case DockInfo::MAXIMIZE:
201 bounds.Offset(0, kDropWindowSize / 2);
202 break;
203 case DockInfo::LEFT_HALF:
204 bounds.Offset(kDropWindowSize / 2, 0);
205 break;
206 case DockInfo::RIGHT_HALF:
207 bounds.Offset(-kDropWindowSize / 2, 0);
208 break;
209 case DockInfo::BOTTOM_HALF:
210 bounds.Offset(0, -kDropWindowSize / 2);
211 break;
212 default:
213 break;
214 }
215
216 popup_ = new views::WidgetWin; 160 popup_ = new views::WidgetWin;
217 popup_->set_window_style(WS_POPUP); 161 popup_->set_window_style(WS_POPUP);
218 popup_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | 162 popup_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW |
219 WS_EX_TOPMOST); 163 WS_EX_TOPMOST);
220 popup_->SetLayeredAlpha(0x00); 164 popup_->SetLayeredAlpha(0x00);
221 popup_->Init(NULL, bounds, false); 165 popup_->Init(NULL, info.GetPopupRect(), false);
222 popup_->SetContentsView(new DockView(info.type())); 166 popup_->SetContentsView(new DockView(info.type()));
223 hot_animation_.Show();
224 if (info.in_enable_area()) 167 if (info.in_enable_area())
225 enable_animation_.Show(); 168 animation_.Reset(1);
169 else
170 animation_.Show();
226 popup_->SetWindowPos(HWND_TOP, 0, 0, 0, 0, 171 popup_->SetWindowPos(HWND_TOP, 0, 0, 0, 0,
227 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOMOVE | SWP_SHOWWINDOW); 172 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOMOVE | SWP_SHOWWINDOW);
228 popup_hwnd_ = popup_->GetHWND(); 173 popup_hwnd_ = popup_->GetHWND();
229 } 174 }
230 175
231 ~DockDisplayer() { 176 ~DockDisplayer() {
232 if (controller_) 177 if (controller_)
233 controller_->DockDisplayerDestroyed(this); 178 controller_->DockDisplayerDestroyed(this);
234 } 179 }
235 180
236 // Updates the state based on |in_enable_area|. 181 // Updates the state based on |in_enable_area|.
237 void UpdateInEnabledArea(bool in_enable_area) { 182 void UpdateInEnabledArea(bool in_enable_area) {
238 if (in_enable_area != in_enable_area_) { 183 if (in_enable_area != in_enable_area_) {
239 in_enable_area_ = in_enable_area; 184 in_enable_area_ = in_enable_area;
240 if (!in_enable_area_) 185 UpdateLayeredAlpha();
241 enable_animation_.Hide();
242 else
243 enable_animation_.Show();
244 } 186 }
245 } 187 }
246 188
247 // Resets the reference to the hosting DraggedTabController. This is invoked 189 // Resets the reference to the hosting DraggedTabController. This is invoked
248 // when the DraggedTabController is destoryed. 190 // when the DraggedTabController is destoryed.
249 void clear_controller() { controller_ = NULL; } 191 void clear_controller() { controller_ = NULL; }
250 192
251 // HWND of the window we create. 193 // HWND of the window we create.
252 HWND popup_hwnd() { return popup_hwnd_; } 194 HWND popup_hwnd() { return popup_hwnd_; }
253 195
254 // Starts the hide animation. When the window is closed the 196 // Starts the hide animation. When the window is closed the
255 // DraggedTabController is notified by way of the DockDisplayerDestroyed 197 // DraggedTabController is notified by way of the DockDisplayerDestroyed
256 // method 198 // method
257 void Hide() { 199 void Hide() {
258 if (hidden_) 200 if (hidden_)
259 return; 201 return;
260 202
261 if (!popup_) { 203 if (!popup_) {
262 delete this; 204 delete this;
263 return; 205 return;
264 } 206 }
265 hidden_ = true; 207 hidden_ = true;
266 enable_animation_.Hide(); 208 animation_.Hide();
267 hot_animation_.Hide();
268 } 209 }
269 210
270 virtual void AnimationProgressed(const Animation* animation) { 211 virtual void AnimationProgressed(const Animation* animation) {
271 popup_->SetLayeredAlpha( 212 UpdateLayeredAlpha();
272 static_cast<BYTE>((hot_animation_.GetCurrentValue() +
273 enable_animation_.GetCurrentValue()) / 2 * 255.0));
274 popup_->GetRootView()->SchedulePaint();
275 } 213 }
276 214
277 virtual void AnimationEnded(const Animation* animation) { 215 virtual void AnimationEnded(const Animation* animation) {
278 if (!hidden_) 216 if (!hidden_)
279 return; 217 return;
280 popup_->Close(); 218 popup_->Close();
281 delete this; 219 delete this;
282 return; 220 }
221
222 virtual void UpdateLayeredAlpha() {
223 double scale = in_enable_area_ ? 1 : .5;
224 popup_->SetLayeredAlpha(
225 static_cast<BYTE>(animation_.GetCurrentValue() * scale * 255.0));
226 popup_->GetRootView()->SchedulePaint();
283 } 227 }
284 228
285 private: 229 private:
286 // DraggedTabController that created us. 230 // DraggedTabController that created us.
287 DraggedTabController* controller_; 231 DraggedTabController* controller_;
288 232
289 // Window we're showing. 233 // Window we're showing.
290 views::WidgetWin* popup_; 234 views::WidgetWin* popup_;
291 235
292 // HWND of |popup_|. We cache this to avoid the possibility of invoking a 236 // HWND of |popup_|. We cache this to avoid the possibility of invoking a
293 // method on popup_ after we close it. 237 // method on popup_ after we close it.
294 HWND popup_hwnd_; 238 HWND popup_hwnd_;
295 239
296 // Animation corresponding to !DockInfo::in_enable_area. 240 // Animation for when first made visible.
297 SlideAnimation hot_animation_; 241 SlideAnimation animation_;
298
299 // Animation corresponding to DockInfo::in_enable_area.
300 SlideAnimation enable_animation_;
301 242
302 // Have we been hidden? 243 // Have we been hidden?
303 bool hidden_; 244 bool hidden_;
304 245
305 // Value of DockInfo::in_enable_area. 246 // Value of DockInfo::in_enable_area.
306 bool in_enable_area_; 247 bool in_enable_area_;
307 }; 248 };
308 249
309 /////////////////////////////////////////////////////////////////////////////// 250 ///////////////////////////////////////////////////////////////////////////////
310 // DraggedTabController, public: 251 // DraggedTabController, public:
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 494 }
554 } 495 }
555 } else if (dock_info_.type() != DockInfo::NONE && 496 } else if (dock_info_.type() != DockInfo::NONE &&
556 !dock_controllers_.empty()) { 497 !dock_controllers_.empty()) {
557 // Current dock position is the same as last, update the controller's 498 // Current dock position is the same as last, update the controller's
558 // in_enable_area state as it may have changed. 499 // in_enable_area state as it may have changed.
559 dock_controllers_.back()->UpdateInEnabledArea(dock_info_.in_enable_area()); 500 dock_controllers_.back()->UpdateInEnabledArea(dock_info_.in_enable_area());
560 } 501 }
561 } 502 }
562 503
563
564 void DraggedTabController::ChangeDraggedContents(TabContents* new_contents) { 504 void DraggedTabController::ChangeDraggedContents(TabContents* new_contents) {
565 if (dragged_contents_) { 505 if (dragged_contents_) {
566 NotificationService::current()->RemoveObserver( 506 NotificationService::current()->RemoveObserver(
567 this, 507 this,
568 NotificationType::TAB_CONTENTS_DESTROYED, 508 NotificationType::TAB_CONTENTS_DESTROYED,
569 Source<TabContents>(dragged_contents_)); 509 Source<TabContents>(dragged_contents_));
570 if (original_delegate_) 510 if (original_delegate_)
571 dragged_contents_->set_delegate(original_delegate_); 511 dragged_contents_->set_delegate(original_delegate_);
572 } 512 }
573 original_delegate_ = NULL; 513 original_delegate_ = NULL;
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 // Move the window to the front. 1164 // Move the window to the front.
1225 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, 1165 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
1226 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); 1166 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1227 1167
1228 // The previous call made the window appear on top of the dragged window, 1168 // The previous call made the window appear on top of the dragged window,
1229 // move the dragged window to the front. 1169 // move the dragged window to the front.
1230 SetWindowPos(view_->GetWidget()->GetHWND(), HWND_TOP, 0, 0, 0, 0, 1170 SetWindowPos(view_->GetWidget()->GetHWND(), HWND_TOP, 0, 0, 0, 0,
1231 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); 1171 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1232 } 1172 }
1233 } 1173 }
OLDNEW
« no previous file with comments | « chrome/browser/dock_info.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698