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

Side by Side Diff: ash/wm/maximize_bubble_controller.cc

Issue 10823025: Adding new maximize menu according to spec (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed radial Created 8 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/wm/maximize_bubble_controller.h"
6
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_animations.h"
10 #include "base/bind.h"
11 #include "base/command_line.h"
msw 2012/08/02 18:56:59 nit: is this include necessary? Please only IWYU.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 I removed the radial menu and it had some tentacle
12 #include "base/message_loop.h"
13 #include "base/timer.h"
14 #include "grit/ash_strings.h"
15 #include "grit/ui_resources.h"
16 #include "ui/aura/aura_switches.h"
msw 2012/08/02 18:56:59 nit: is this include necessary? Please only IWYU.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
17 #include "ui/base/ui_base_switches.h"
msw 2012/08/02 18:56:59 nit: is this include necessary? Please only IWYU.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
18 #include "ui/aura/event.h"
19 #include "ui/aura/focus_manager.h"
20 #include "ui/aura/window.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/screen.h"
25 #include "ui/views/bubble/bubble_delegate.h"
26 #include "ui/views/bubble/bubble_frame_view.h"
27 #include "ui/views/controls/button/button.h"
28 #include "ui/views/controls/button/custom_button.h"
29 #include "ui/views/controls/label.h"
30 #include "ui/views/events/event.h"
31 #include "ui/views/layout/box_layout.h"
32
33 namespace {
34
35 // The command codes returned from the radial menu.
36 enum RadialMenuCommands {
sky 2012/08/02 18:30:30 Remove this.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
37 RADIAL_MENU_NONE = 0,
38 RADIAL_MENU_RIGHT,
39 RADIAL_MENU_MINIMIZE,
40 RADIAL_MENU_LEFT
41 };
42
43 // Bubble constants
msw 2012/08/02 18:56:59 nit: Nix comment or extrapolate and append a perio
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
44 const int kMaximumBubbleWidth = 200;
45 const int kArrowOffset = 10;
msw 2012/08/02 18:56:59 nit: is this used?
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
46
47 // The spacing between two buttons.
48 const int kLayoutSpacing = 1;
49
50 const int kAnimationDurationForPopupMS = 200;
msw 2012/08/02 18:56:59 nit: move down with kBubbleAppearanceDelay or vice
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
51
52 // The background color
53 const SkColor kBubbleBackgroundColor = 0xc8141414;
54
55 // The text color within the bubble
56 const SkColor kBubbleTextColor = 0xffffffff;
msw 2012/08/02 18:56:59 nit: Use SK_ColorWHITE (or theme service/provider
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
57
58 // The line width of the bubble.
msw 2012/08/02 18:56:59 nit: s/width/height/
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
59 const int kLineHeight = 1;
60
61 // The pixel dimensions of the arrow
msw 2012/08/02 18:56:59 nit: append a period.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
62 const int kArrowHeight = 10;
63 const int kArrowWidth = 20;
64
65 // The delay of the bubble appearance.
66 const int kBubbleAppearanceDelay = 200; // msec
sky 2012/08/02 18:30:30 nit: name MS like you did on line 50 to make it cl
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
67
68 // The active area behind a segment in a radial menu (in segment widths):
69 // In case of hover the user wants to cancel out when getting reasonably far
70 // away from the menu - in this case three times the wedge radius.
71 const int kHoverRadialMenuExtension = 3;
sky 2012/08/02 18:30:30 Remove the constants you aren't using in this patc
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 You are right. That slipped through
72 // In contrast to a hover action as given by |kHoverRadialMenuExtension|, the
73 // user does want to drag his finger / mouse much further away from the menu
74 // without canceling out (e.g. when doing a 'flic/swipe'). To allow 'endless
75 // distance' a 'big number' is given.
76 const int kDragRadialMenuExtension = 10000;
msw 2012/08/02 18:56:59 nit: is this still used?
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Was already deleted.
77
78 class MaximizeBubbleBorder : public views::BubbleBorder {
msw 2012/08/02 18:56:59 Can this work be merged with existing/needed bubbl
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 I have spent at least two to three days trying to
msw 2012/08/03 19:58:54 Take a look at Varun's work in codereview.chromium
79 public:
80 MaximizeBubbleBorder(views::View* content_view,
msw 2012/08/02 18:56:59 nit: Do not use inline definitions here and below.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
81 views::View* anchor)
82 : views::BubbleBorder(views::BubbleBorder::TOP_RIGHT,
83 views::BubbleBorder::NO_SHADOW),
84 anchor_(anchor),
85 content_view_(content_view) {
86 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
87 }
88
89 virtual ~MaximizeBubbleBorder() {}
90
91 // Overridden from views::BubbleBorder to match the design specs.
92 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to,
93 const gfx::Size& contents_size) const OVERRIDE {
94 gfx::Size border_size(contents_size);
95 gfx::Insets insets;
96 GetInsets(&insets);
97 border_size.Enlarge(insets.width(), insets.height());
98
99 // Position the bubble to center the box on the anchor.
msw 2012/08/02 18:56:59 Can this be accomplished via ArrowLocation and Set
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 The designer requests states that the button shoul
msw 2012/08/03 19:58:54 Ok, consider adding a TODO to support centered arr
100 int x = -insets.left() -
msw 2012/08/02 18:56:59 Can this be obtained from a view's origin point?
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 This code has slightly changes after I got the fin
msw 2012/08/03 19:58:54 Ok, this seems fine, thanks.
101 (border_size.width() - anchor_->width() - kArrowWidth) / 2;
102 // Position the bubble under the anchor, overlapping the arrow with it.
103 int y = anchor_->height() - insets.top();
104
105 gfx::Point view_topleft(x, y);
msw 2012/08/02 18:56:59 nit: is this a view origin? please rename.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
106 views::View::ConvertPointToScreen(anchor_, &view_topleft);
107
108 return gfx::Rect(view_topleft.x(), view_topleft.y(),
msw 2012/08/02 18:56:59 nit: use Rect(const gfx::Point& origin, const gfx:
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
109 border_size.width(), border_size.height());
110 }
111
112 // Overridden from views::Border
113 virtual void Paint(const views::View& view,
msw 2012/08/02 18:56:59 Again, why does this require custom code?
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 See above.
114 gfx::Canvas* canvas) const OVERRIDE {
115 gfx::Insets inset;
116 GetInsets(&inset);
117
118 // Draw the border line around everything.
119 int y = inset.top();
120 // Top
121 canvas->FillRect(gfx::Rect(inset.left(),
122 y - kLineHeight,
123 content_view_->width(),
124 kLineHeight),
125 kBubbleBackgroundColor);
126 // Bottom
127 canvas->FillRect(gfx::Rect(inset.left(),
128 y + content_view_->height(),
129 content_view_->width(),
130 kLineHeight),
131 kBubbleBackgroundColor);
132 // Left
133 canvas->FillRect(gfx::Rect(inset.left() - kLineHeight,
134 y - kLineHeight,
135 kLineHeight,
136 content_view_->height() + 2 * kLineHeight),
137 kBubbleBackgroundColor);
138 // Right
139 canvas->FillRect(gfx::Rect(inset.left() + content_view_->width(),
140 y - kLineHeight,
141 kLineHeight,
142 content_view_->height() + 2 * kLineHeight),
143 kBubbleBackgroundColor);
144
145 // Draw the arrow afterwards covering the border.
146 SkPath path;
147 path.incReserve(4);
148 // The center of the tip should be in the middle of the button.
149 int tip_x = inset.left() + content_view_->width() / 2;
150 int left_base_x = tip_x - kArrowWidth / 2;
151 int left_base_y = y;
152 int tip_y = left_base_y - kArrowHeight;
153 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y));
154 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
155 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth),
156 SkIntToScalar(left_base_y));
157
158 SkPaint paint;
159 paint.setStyle(SkPaint::kFill_Style);
160 paint.setColor(kBubbleBackgroundColor);
161 canvas->DrawPath(path, paint);
162 }
163
164 private:
165 views::View* anchor_;
166 views::View* content_view_;
167
168 DISALLOW_COPY_AND_ASSIGN(MaximizeBubbleBorder);
169 };
170
171 } // namespace
172
173 namespace ash {
174
175 // The image button gets overridden to be able to capture mouse hover events.
176 class MaximizeBubbleController::BubbleMenuButton : public views::ImageButton {
msw 2012/08/02 18:56:59 This seems odd, can't each button handle mouse ent
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 You only get clicked events no hover events from C
msw 2012/08/03 19:58:54 Ah, I think I just misunderstood what you're doing
177 public:
178 explicit BubbleMenuButton(
179 MaximizeBubbleController::BubbleContentsButtonRow* button_row_listener);
180 virtual ~BubbleMenuButton() {}
181
182 // CustomButton overrides:
183 virtual void OnMouseCaptureLost() OVERRIDE;
184 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
185 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
186
187 private:
188 // The creating class which needs to get notified in case of a hover event.
189 MaximizeBubbleController::BubbleContentsButtonRow* button_row_;
190
191 DISALLOW_COPY_AND_ASSIGN(BubbleMenuButton);
192 };
193
194 // The class which creates and manages the bubble menu element.
195 // It creates a "bubble border" and the content accordingly.
msw 2012/08/02 18:56:59 nit: nix quotes around bubble border.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Why is that? Done
msw 2012/08/03 19:58:54 I typically reserve quotes for actual quotations,
196 // Note: Since the SnapSizer will show animations on top of the maximize button
197 // this menu gets creates as a separate window and the SnapSizer will be
msw 2012/08/02 18:56:59 nit: "gets creates" and "will be creates"
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
198 // creates underneath this window.
199 class MaximizeBubbleController::Bubble : public views::BubbleDelegateView {
200 public:
201 explicit Bubble(MaximizeBubbleController* owner);
202 virtual ~Bubble();
203
204 // The window of the menu under which the SnapSizer will get created.
205 aura::Window* GetMenuWindow();
206
207 // Overridden from views::BubbleDelegateView.
208 virtual gfx::Rect GetAnchorRect() const OVERRIDE;
209
210 // Overridden from View
msw 2012/08/02 18:56:59 nit: add a period for consistency.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
211 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
212 virtual void OnClickedOutsideView() OVERRIDE;
213
214 // Overridden from views::View.
215 virtual gfx::Size GetPreferredSize() OVERRIDE;
216
217 // Overridden from views::Widget::Observer.
218 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
219
220 // Called from the owning class to indicate that the menu should get
msw 2012/08/02 18:56:59 nit: use "controller" or owner terminology consist
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
221 // destroyed.
222 virtual void OwnerRequestsCloseAndDelete();
223
224 // Called from the owning class to change the menu content to the given
225 // |snap_type| so that the user knows what is selected.
226 void SetMenuState(FrameMaximizeButton::SnapType snap_type);
sky 2012/08/02 18:30:30 SetSnapType
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
227
228 // Get the owning MaximizeBubbleController. This might return NULL in case
229 // of an asynchronous shutdown.
230 MaximizeBubbleController* GetOwner() {
sky 2012/08/02 18:30:30 Name this owner()
msw 2012/08/02 18:56:59 Make this MaximizeBubbleController* owner() const
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
231 return owner_;
232 }
233
234 private:
235 // True if the shut down has been initiated.
236 bool shutting_down_;
237
238 // Our owning class.
239 MaximizeBubbleController* owner_;
240
241 // The widget which contains our menu and the bubble border.
242 views::Widget* bubble_widget_;
243
244 // The content accessor of the menu.
245 BubbleContentsView* contents_view_;
246
247 DISALLOW_COPY_AND_ASSIGN(Bubble);
248 };
249
250 // A class that creates all buttons and put them into a view.
msw 2012/08/02 18:56:59 This seems unnecessary, just do this in BubbleCont
msw 2012/08/03 19:58:54 I still think this separate class is somewhat unne
251 class MaximizeBubbleController::BubbleContentsButtonRow
252 : public views::View,
253 public views::ButtonListener {
254 public:
255 explicit BubbleContentsButtonRow(MaximizeBubbleController::Bubble* bubble)
256 : bubble_(bubble),
257 left_button_(NULL),
258 minimize_button_(NULL),
259 right_button_(NULL) {
260 SetLayoutManager(new views::BoxLayout(
261 views::BoxLayout::kHorizontal, 0, 0, kLayoutSpacing));
262 set_background(
263 views::Background::CreateSolidBackground(kBubbleBackgroundColor));
264
265 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
266 left_button_ = new MaximizeBubbleController::BubbleMenuButton(this);
267 left_button_->SetImage(views::CustomButton::BS_NORMAL,
sky 2012/08/02 18:30:30 Create a function for constructor that can be shar
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
268 // TODO(skuhne): Replace images as soon as they come in.
269 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P));
270 left_button_->SetImage(views::CustomButton::BS_HOT,
271 // TODO(skuhne): Replace images as soon as they come in.
msw 2012/08/02 18:56:59 nit: consolidate redundant TODO comments.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Got the artwork in the meantime and added it accor
272 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P));
273 left_button_->SetImage(views::CustomButton::BS_PUSHED,
274 // TODO(skuhne): Replace images as soon as they come in.
275 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P));
276 AddChildView(left_button_);
277
278 minimize_button_ = new MaximizeBubbleController::BubbleMenuButton(this);
279 minimize_button_->SetImage(views::CustomButton::BS_NORMAL,
280 // TODO(skuhne): Replace images as soon as they come in.
281 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P));
282 minimize_button_->SetImage(views::CustomButton::BS_HOT,
283 // TODO(skuhne): Replace images as soon as they come in.
284 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P));
285 minimize_button_->SetImage(views::CustomButton::BS_PUSHED,
286 // TODO(skuhne): Replace images as soon as they come in.
287 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P));
288 AddChildView(minimize_button_);
289
290 right_button_ = new MaximizeBubbleController::BubbleMenuButton(this);
291 right_button_->SetImage(views::CustomButton::BS_NORMAL,
292 // TODO(skuhne): Replace images as soon as they come in.
293 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P));
294 right_button_->SetImage(views::CustomButton::BS_HOT,
295 // TODO(skuhne): Replace images as soon as they come in.
296 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P));
297 right_button_->SetImage(views::CustomButton::BS_PUSHED,
298 // TODO(skuhne): Replace images as soon as they come in.
299 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P));
300 AddChildView(right_button_);
301 }
302
303 virtual ~BubbleContentsButtonRow() {}
304
305 // Overridden from ButtonListener.
306 virtual void ButtonPressed(views::Button* sender,
307 const views::Event& event) OVERRIDE {
308 if (!bubble_->GetOwner())
sky 2012/08/02 18:30:30 Why do you need this? At a minimum add a comment (
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
309 return;
310 if (sender == left_button_)
311 bubble_->GetOwner()->OnButtonClicked(FrameMaximizeButton::SNAP_LEFT);
312 else if (sender == minimize_button_)
313 bubble_->GetOwner()->OnButtonClicked(FrameMaximizeButton::SNAP_MINIMIZE);
314 else if (sender == right_button_)
315 bubble_->GetOwner()->OnButtonClicked(FrameMaximizeButton::SNAP_RIGHT);
316 else {
317 NOTREACHED() << "Unknown button pressed.";
318 }
319 }
320
321 // Called from BubbleMenuButton.
322 void ButtonHovered(MaximizeBubbleController::BubbleMenuButton* sender) {
323 if (!bubble_->GetOwner())
324 return;
325 if (sender == left_button_)
326 bubble_->GetOwner()->OnButtonHover(FrameMaximizeButton::SNAP_LEFT);
327 else if (sender == minimize_button_)
328 bubble_->GetOwner()->OnButtonHover(FrameMaximizeButton::SNAP_MINIMIZE);
329 else if (sender == right_button_)
330 bubble_->GetOwner()->OnButtonHover(FrameMaximizeButton::SNAP_RIGHT);
331 else
332 bubble_->GetOwner()->OnButtonHover(FrameMaximizeButton::SNAP_NONE);
333 }
334
335 private:
336 // The owning object which gets notifications.
337 MaximizeBubbleController::Bubble* bubble_;
338
339 // The created buttons for our menu.
340 MaximizeBubbleController::BubbleMenuButton* left_button_;
341 MaximizeBubbleController::BubbleMenuButton* minimize_button_;
342 MaximizeBubbleController::BubbleMenuButton* right_button_;
343
344 DISALLOW_COPY_AND_ASSIGN(BubbleContentsButtonRow);
345 };
346
347 // A class which creates the content of the bubble: The buttons, and the label.
348 class MaximizeBubbleController::BubbleContentsView : public views::View {
349 public:
350 explicit BubbleContentsView(MaximizeBubbleController::Bubble* bubble)
351 : bubble_(bubble),
352 buttons_view_(NULL),
353 label_view_(NULL) {
354 SetLayoutManager(new views::BoxLayout(
355 views::BoxLayout::kVertical, 0, 0, kLayoutSpacing));
356 set_background(
357 views::Background::CreateSolidBackground(kBubbleBackgroundColor));
358
359 buttons_view_ = new BubbleContentsButtonRow(bubble);
360 AddChildView(buttons_view_);
361
362 label_view_ = new views::Label();
363 SetMenuState(FrameMaximizeButton::SNAP_NONE);
364 label_view_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
365 label_view_->SetBackgroundColor(kBubbleBackgroundColor);
366 label_view_->SetEnabledColor(kBubbleTextColor);
367 AddChildView(label_view_);
368 }
369
370 virtual ~BubbleContentsView() {}
371
372 // Set the label content to reflect the currently selected |snap_type|.
373 // This function can be executed through the frame maximize button as well as
374 // through hover operations.
375 void SetMenuState(FrameMaximizeButton::SnapType snap_type) {
sky 2012/08/02 18:30:30 SetSnapType()
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
376 if (!bubble_->GetOwner())
377 return;
378
379 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
380 switch (snap_type) {
381 case FrameMaximizeButton::SNAP_LEFT:
382 label_view_->SetText(rb.GetLocalizedString(IDS_ASH_SNAP_WINDOW_LEFT));
383 return;
384 case FrameMaximizeButton::SNAP_RIGHT:
385 label_view_->SetText(rb.GetLocalizedString(IDS_ASH_SNAP_WINDOW_RIGHT));
386 return;
387 case FrameMaximizeButton::SNAP_MAXIMIZE:
388 DCHECK(!bubble_->GetOwner()->is_maximized());
389 label_view_->SetText(rb.GetLocalizedString(IDS_ASH_MAXIMIZE_WINDOW));
390 return;
391 case FrameMaximizeButton::SNAP_MINIMIZE:
392 label_view_->SetText(rb.GetLocalizedString(IDS_ASH_MINIMIZE_WINDOW));
393 return;
394 case FrameMaximizeButton::SNAP_RESTORE:
395 DCHECK(bubble_->GetOwner()->is_maximized());
396 label_view_->SetText(rb.GetLocalizedString(IDS_ASH_RESTORE_WINDOW));
397 return;
398 default:
399 // If nothing is selected, we automatically select the click operation.
400 label_view_->SetText(rb.GetLocalizedString(
401 bubble_->GetOwner()->is_maximized() ? IDS_ASH_RESTORE_WINDOW :
402 IDS_ASH_MAXIMIZE_WINDOW));
403 return;
404 }
405 }
406
407 private:
408 // The owning class.
409 MaximizeBubbleController::Bubble* bubble_;
410
411 // The object which owns all the buttons.
412 BubbleContentsButtonRow* buttons_view_;
413
414 // The label object which shows the user the selected action.
415 views::Label* label_view_;
416
417 DISALLOW_COPY_AND_ASSIGN(BubbleContentsView);
418 };
419
420 MaximizeBubbleController::BubbleMenuButton::BubbleMenuButton(
421 MaximizeBubbleController::BubbleContentsButtonRow* button_row)
422 : views::ImageButton(button_row),
423 button_row_(button_row) {}
424
425 void MaximizeBubbleController::BubbleMenuButton::OnMouseCaptureLost(
426 ) OVERRIDE {
sky 2012/08/02 18:30:30 Don't wrap like this.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
427 button_row_->ButtonHovered(NULL);
428 views::ImageButton::OnMouseCaptureLost();
429 }
430
431 void MaximizeBubbleController::BubbleMenuButton::OnMouseEntered(
432 const views::MouseEvent& event) OVERRIDE {
433 button_row_->ButtonHovered(this);
434 views::ImageButton::OnMouseEntered(event);
435 }
436
437 void MaximizeBubbleController::BubbleMenuButton::OnMouseExited(
438 const views::MouseEvent& event) OVERRIDE {
439 button_row_->ButtonHovered(NULL);
440 views::ImageButton::OnMouseExited(event);
441 }
442
443 MaximizeBubbleController::Bubble::Bubble(MaximizeBubbleController* owner)
444 : views::BubbleDelegateView(owner->frame_maximize_button(),
445 views::BubbleBorder::TOP_RIGHT),
446 shutting_down_(false),
447 owner_(owner),
448 bubble_widget_(NULL),
449 contents_view_(NULL) {
450 set_margins(gfx::Insets());
451
452 // The window needs to be owned by the root so that the SnapSizer does not
453 // cover it upon animation.
454 aura::Window* parent = Shell::GetContainer(
455 Shell::GetActiveRootWindow(),
456 internal::kShellWindowId_LauncherContainer);
457 set_parent_window(parent);
458
459 set_notify_enter_exit_on_child(true);
460 set_try_mirroring_arrow(false);
461 SetPaintToLayer(true);
462 SetFillsBoundsOpaquely(false);
463 set_color(kBubbleBackgroundColor);
464 set_close_on_deactivate(false);
465 set_background(
466 views::Background::CreateSolidBackground(kBubbleBackgroundColor));
467
468 SetLayoutManager(new views::BoxLayout(
469 views::BoxLayout::kVertical, 0, 0, kLayoutSpacing));
470
471 contents_view_ = new BubbleContentsView(this);
472 AddChildView(contents_view_);
473
474 // Note that the returned widget has an observer which points to our
475 // functions.
476 bubble_widget_ = views::BubbleDelegateView::CreateBubble(this);
477
478 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
479 bubble_widget_->non_client_view()->frame_view()->set_background(NULL);
480
481 MaximizeBubbleBorder* bubble_border = new MaximizeBubbleBorder(
482 this,
483 anchor_view());
484 GetBubbleFrameView()->SetBubbleBorder(bubble_border);
485 GetBubbleFrameView()->set_background(NULL);
486
487 // Recalculate size with new border.
488 SizeToContents();
489
490 // Setup animation.
491 ash::SetWindowVisibilityAnimationType(
492 bubble_widget_->GetNativeWindow(),
493 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
494 ash::SetWindowVisibilityAnimationTransition(
495 bubble_widget_->GetNativeWindow(),
496 ash::ANIMATE_BOTH);
497 ash::SetWindowVisibilityAnimationDuration(
498 bubble_widget_->GetNativeWindow(),
499 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS));
500
501 Show();
502 // We don't want to loose the focus on our parent window because the button
msw 2012/08/02 18:56:59 nit: s/loose/lose/ here and below.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
503 // would otherwise loose the highlight when the "helper bubble" is shown.
504 views::Widget* widget =
505 owner_->frame_maximize_button()->parent()->GetWidget();
506 if (widget) {
507 aura::Window* parent_window = widget->GetNativeWindow();
508 parent_window->GetFocusManager()->SetFocusedWindow(parent_window, NULL);
509 }
510 }
511
512 MaximizeBubbleController::Bubble::~Bubble() {
513 LOG(ERROR) << "~Bubble";
514 }
515
516 aura::Window* MaximizeBubbleController::Bubble::GetMenuWindow() {
517 return bubble_widget_ ? bubble_widget_->GetNativeWindow() : NULL;
518 }
519
520 gfx::Rect MaximizeBubbleController::Bubble::GetAnchorRect() const OVERRIDE {
521 if (!owner_)
522 return gfx::Rect();
523
524 gfx::Rect anchor_rect =
525 owner_->frame_maximize_button()->GetBoundsInScreen();
526 return anchor_rect;
527 }
528
529 void MaximizeBubbleController::Bubble::OnMouseExited(
530 const views::MouseEvent& event) OVERRIDE {
531 if (!owner_ || shutting_down_)
532 return;
533 // When we leave the bubble, we might be still be in gesture mode or over
534 // the maximize button. So only close if none of the other cases apply.
535 if (!owner_->frame_maximize_button()->is_snap_enabled()) {
536 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint();
537 if (!owner_->frame_maximize_button()->GetBoundsInScreen().Contains(
538 screen_location)) {
539 owner_->RequestDestructionThroughOwner();
540 }
541 }
542 }
543
544 void MaximizeBubbleController::Bubble::OnClickedOutsideView() OVERRIDE {
545 if (!owner_ || shutting_down_)
546 return;
547 // Don't destroy the menu when the click happened while the user is
548 // performing a dragging operation.
549 if (!owner_->frame_maximize_button()->is_snap_enabled())
550 owner_->RequestDestructionThroughOwner();
551 }
552
553 gfx::Size MaximizeBubbleController::Bubble::GetPreferredSize() OVERRIDE {
554 return contents_view_->GetPreferredSize();
555 }
556
557 void MaximizeBubbleController::Bubble::OnWidgetClosing(
558 views::Widget* widget) OVERRIDE {
559 if (bubble_widget_ != widget)
560 return;
561
562 if (owner_) {
563 // If the bubble destruction was triggered by some other external influence
564 // then ourselves, the owner needs to be informed that the menu is gone.
565 shutting_down_ = true;
566 owner_->RequestDestructionThroughOwner();
567 owner_ = NULL;
568 }
569 // Remove any existing observers.
570 bubble_widget_->RemoveObserver(this);
571 anchor_widget()->RemoveObserver(this);
572 }
573
574 void MaximizeBubbleController::Bubble::OwnerRequestsCloseAndDelete() {
575 // This only gets called from the owning base class once it is deleted.
576 if (shutting_down_)
577 return;
578 shutting_down_ = true;
579 owner_ = NULL;
580
581 // Close the widget asynchronously.
582 bubble_widget_->Close();
583 }
584
585 void MaximizeBubbleController::Bubble::SetMenuState(
586 FrameMaximizeButton::SnapType snap_type) {
587 if (contents_view_)
588 contents_view_->SetMenuState(snap_type);
589 }
590
591 MaximizeBubbleController::MaximizeBubbleController(
592 FrameMaximizeButton* frame_maximize_button,
593 bool is_maximized)
594 : frame_maximize_button_(frame_maximize_button),
595 bubble_(NULL),
596 is_maximized_(is_maximized) {
597 // Create the task which will create the bubble delayed.
598 base::OneShotTimer<MaximizeBubbleController>* new_timer =
599 new base::OneShotTimer<MaximizeBubbleController>();
600 new_timer->Start(
601 FROM_HERE,
602 base::TimeDelta::FromMilliseconds(kBubbleAppearanceDelay),
603 this,
604 &MaximizeBubbleController::DelayedBubbleCreation);
605 timer_.reset(new_timer);
606 }
607
608 void MaximizeBubbleController::DelayCreation() {
609 if (timer_.get() && timer_->IsRunning())
610 timer_->Reset();
611 }
612
613 void MaximizeBubbleController::DelayedBubbleCreation() {
614 if (!bubble_) {
msw 2012/08/02 18:56:59 nit: remove {}
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
615 bubble_ = new Bubble(this);
616 }
617 timer_->Stop();
618 }
619
620 MaximizeBubbleController::~MaximizeBubbleController() {
sky 2012/08/02 18:30:30 Order doesn't match header.
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 Done.
621 // Note: The destructor only gets initiated through the owner.
622 timer_.reset(NULL);
623 if (bubble_) {
624 bubble_->OwnerRequestsCloseAndDelete();
625 bubble_ = NULL;
626 }
627 }
628
629 void MaximizeBubbleController::RequestDestructionThroughOwner() {
630 // Tell the parent to destroy us (if this didn't happen yet).
631 if (timer_.get()) {
632 timer_.reset(NULL);
633 // Informs the owner that the menu is gone and requests |this| destruction.
634 frame_maximize_button_->DestroyMaximizeMenu();
635 // Note: After this call |this| is destroyed.
636 }
637 }
638
639 void MaximizeBubbleController::OnButtonClicked(
640 FrameMaximizeButton::SnapType snap_type) {
641 frame_maximize_button_->ExecuteSnapAndCloseMenu(snap_type);
642 }
643
644 void MaximizeBubbleController::OnButtonHover(
645 FrameMaximizeButton::SnapType snap_type) {
646 frame_maximize_button_->SnapButtonHovered(snap_type);
647 }
648
649 void MaximizeBubbleController::SetMenuState(
650 FrameMaximizeButton::SnapType snap_type) {
651 if (bubble_)
msw 2012/08/02 18:56:59 Should this instead DCHECK(bubble_) as it should o
Mr4D (OOO till 08-26) 2012/08/02 23:10:38 The short answer is: No. The bubble lives and dies
652 bubble_->SetMenuState(snap_type);
653 }
654
655 aura::Window* MaximizeBubbleController::GetMenuWindow() {
656 return bubble_ ? bubble_->GetMenuWindow() : NULL;
657 }
658
659 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698