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

Side by Side Diff: ash/system/tray/system_tray_bubble.cc

Issue 10381132: Allow Uber Tray popup pointing to the related tray item view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ash/system/tray/system_tray_bubble.h" 5 #include "ash/system/tray/system_tray_bubble.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/system/tray/system_tray.h" 9 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/system_tray_item.h" 10 #include "ash/system/tray/system_tray_item.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBackground); 169 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBackground);
170 }; 170 };
171 171
172 class SystemTrayBubbleBorder : public views::BubbleBorder { 172 class SystemTrayBubbleBorder : public views::BubbleBorder {
173 public: 173 public:
174 enum ArrowType { 174 enum ArrowType {
175 ARROW_TYPE_NONE, 175 ARROW_TYPE_NONE,
176 ARROW_TYPE_BOTTOM, 176 ARROW_TYPE_BOTTOM,
177 }; 177 };
178 178
179 SystemTrayBubbleBorder(views::View* owner, ArrowType arrow_type) 179 SystemTrayBubbleBorder(views::View* owner,
180 ArrowType arrow_type,
181 int arrow_offset)
180 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, 182 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT,
181 views::BubbleBorder::NO_SHADOW), 183 views::BubbleBorder::NO_SHADOW),
182 owner_(owner), 184 owner_(owner),
183 arrow_type_(arrow_type) { 185 arrow_type_(arrow_type),
186 arrow_offset_(arrow_offset) {
184 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 187 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
185 } 188 }
186 189
187 virtual ~SystemTrayBubbleBorder() {} 190 virtual ~SystemTrayBubbleBorder() {}
188 191
189 private: 192 private:
190 // Overridden from views::Border. 193 // Overridden from views::Border.
191 virtual void Paint(const views::View& view, 194 virtual void Paint(const views::View& view,
192 gfx::Canvas* canvas) const OVERRIDE { 195 gfx::Canvas* canvas) const OVERRIDE {
193 gfx::Insets inset; 196 gfx::Insets inset;
194 GetInsets(&inset); 197 GetInsets(&inset);
195 DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(), 198 DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(),
196 inset); 199 inset);
197 200
198 // Draw the bottom line. 201 // Draw the bottom line.
199 int y = owner_->height() + 1; 202 int y = owner_->height() + 1;
200 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(), 203 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(),
201 kBottomLineHeight), kBorderDarkColor); 204 kBottomLineHeight), kBorderDarkColor);
202 205
203 if (!Shell::GetInstance()->shelf()->IsVisible()) 206 if (!Shell::GetInstance()->shelf()->IsVisible())
204 return; 207 return;
205 208
206 // Draw the arrow. 209 // Draw the arrow.
207 if (arrow_type_ == ARROW_TYPE_BOTTOM) { 210 if (arrow_type_ == ARROW_TYPE_BOTTOM) {
208 int left_base_x = base::i18n::IsRTL() ? kArrowWidth : 211 int left_base_x = base::i18n::IsRTL() ? kArrowWidth :
209 owner_->width() - kArrowPaddingFromRight - kArrowWidth; 212 owner_->width() - kArrowPaddingFromRight - kArrowWidth;
210 int left_base_y = y; 213 int left_base_y = y;
211 int tip_x = left_base_x + kArrowWidth / 2; 214 int tip_x = left_base_x + kArrowWidth / 2;
212 int tip_y = left_base_y + kArrowHeight; 215 int tip_y = left_base_y + kArrowHeight;
216 if (arrow_offset_ >= kArrowWidth / 2 &&
217 arrow_offset_ < owner_->width() - kArrowWidth / 2) {
218 tip_x = base::i18n::IsRTL() ?
219 arrow_offset_ : owner_->width() - arrow_offset_;
220 left_base_x = tip_x - kArrowWidth / 2;
221 }
sadrul 2012/05/15 02:18:15 I am not sure I understand this. What does this do
Jun Mukai 2012/05/15 02:43:05 Done.
222
213 SkPath path; 223 SkPath path;
214 path.incReserve(4); 224 path.incReserve(4);
215 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); 225 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y));
216 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); 226 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
217 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), 227 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth),
218 SkIntToScalar(left_base_y)); 228 SkIntToScalar(left_base_y));
219 229
220 SkPaint paint; 230 SkPaint paint;
221 paint.setStyle(SkPaint::kFill_Style); 231 paint.setStyle(SkPaint::kFill_Style);
222 paint.setColor(kHeaderBackgroundColorDark); 232 paint.setColor(kHeaderBackgroundColorDark);
223 canvas->DrawPath(path, paint); 233 canvas->DrawPath(path, paint);
224 234
225 // Now draw the arrow border. 235 // Now draw the arrow border.
226 paint.setStyle(SkPaint::kStroke_Style); 236 paint.setStyle(SkPaint::kStroke_Style);
227 paint.setColor(kBorderDarkColor); 237 paint.setColor(kBorderDarkColor);
228 canvas->DrawPath(path, paint); 238 canvas->DrawPath(path, paint);
229 } 239 }
230 } 240 }
231 241
232 views::View* owner_; 242 views::View* owner_;
233 ArrowType arrow_type_; 243 ArrowType arrow_type_;
244 const int arrow_offset_;
234 245
235 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); 246 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder);
236 }; 247 };
237 248
238 } // namespace 249 } // namespace
239 250
240 namespace internal { 251 namespace internal {
241 252
242 // SystemTrayBubbleView 253 // SystemTrayBubbleView
243 254
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { 322 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) {
312 if (host_) 323 if (host_)
313 host_->StopAutoCloseTimer(); 324 host_->StopAutoCloseTimer();
314 } 325 }
315 326
316 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { 327 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) {
317 if (host_) 328 if (host_)
318 host_->RestartAutoCloseTimer(); 329 host_->RestartAutoCloseTimer();
319 } 330 }
320 331
332 // SystemTrayBubble::InitParams
333 SystemTrayBubble::InitParams::InitParams(
334 SystemTrayBubble::AnchorType anchor_type)
335 : anchor(NULL),
336 anchor_type(anchor_type),
337 can_activate(false),
338 login_status(ash::user::LOGGED_IN_NONE),
339 arrow_offset(-1) {
sadrul 2012/05/15 02:18:15 Initialize offset to kArrowPaddingFromRight
Jun Mukai 2012/05/15 02:43:05 Done.
340 }
341
321 // SystemTrayBubble 342 // SystemTrayBubble
322 343
323 SystemTrayBubble::SystemTrayBubble( 344 SystemTrayBubble::SystemTrayBubble(
324 ash::SystemTray* tray, 345 ash::SystemTray* tray,
325 const std::vector<ash::SystemTrayItem*>& items, 346 const std::vector<ash::SystemTrayItem*>& items,
326 BubbleType bubble_type) 347 BubbleType bubble_type)
327 : tray_(tray), 348 : tray_(tray),
328 bubble_view_(NULL), 349 bubble_view_(NULL),
329 bubble_widget_(NULL), 350 bubble_widget_(NULL),
330 items_(items), 351 items_(items),
(...skipping 11 matching lines...) Expand all
342 // Reset the host pointer in bubble_view_ in case its destruction is deferred. 363 // Reset the host pointer in bubble_view_ in case its destruction is deferred.
343 if (bubble_view_) 364 if (bubble_view_)
344 bubble_view_->reset_host(); 365 bubble_view_->reset_host();
345 if (bubble_widget_) { 366 if (bubble_widget_) {
346 bubble_widget_->RemoveObserver(this); 367 bubble_widget_->RemoveObserver(this);
347 // This triggers the destruction of bubble_view_. 368 // This triggers the destruction of bubble_view_.
348 bubble_widget_->Close(); 369 bubble_widget_->Close();
349 } 370 }
350 } 371 }
351 372
352 void SystemTrayBubble::InitView(views::View* anchor, 373 void SystemTrayBubble::InitView(const InitParams& init_params) {
353 AnchorType anchor_type,
354 bool can_activate,
355 ash::user::LoginStatus login_status) {
356 DCHECK(bubble_view_ == NULL); 374 DCHECK(bubble_view_ == NULL);
357 anchor_type_ = anchor_type; 375 anchor_type_ = init_params.anchor_type;
358 bubble_view_ = new SystemTrayBubbleView(anchor, this, can_activate); 376 bubble_view_ = new SystemTrayBubbleView(
377 init_params.anchor, this, init_params.can_activate);
359 378
360 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); 379 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin();
361 it != items_.end(); 380 it != items_.end();
362 ++it) { 381 ++it) {
363 views::View* view = NULL; 382 views::View* view = NULL;
364 switch (bubble_type_) { 383 switch (bubble_type_) {
365 case BUBBLE_TYPE_DEFAULT: 384 case BUBBLE_TYPE_DEFAULT:
366 view = (*it)->CreateDefaultView(login_status); 385 view = (*it)->CreateDefaultView(init_params.login_status);
367 break; 386 break;
368 case BUBBLE_TYPE_DETAILED: 387 case BUBBLE_TYPE_DETAILED:
369 view = (*it)->CreateDetailedView(login_status); 388 view = (*it)->CreateDetailedView(init_params.login_status);
370 break; 389 break;
371 case BUBBLE_TYPE_NOTIFICATION: 390 case BUBBLE_TYPE_NOTIFICATION:
372 view = (*it)->CreateNotificationView(login_status); 391 view = (*it)->CreateNotificationView(init_params.login_status);
373 break; 392 break;
374 } 393 }
375 if (view) 394 if (view)
376 bubble_view_->AddChildView(new TrayPopupItemContainer(view)); 395 bubble_view_->AddChildView(new TrayPopupItemContainer(view));
377 } 396 }
378 397
379 DCHECK(bubble_widget_ == NULL); 398 DCHECK(bubble_widget_ == NULL);
380 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); 399 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
381 400
382 // Must occur after call to CreateBubble() 401 // Must occur after call to CreateBubble()
383 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 402 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
384 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); 403 bubble_widget_->non_client_view()->frame_view()->set_background(NULL);
385 SystemTrayBubbleBorder::ArrowType arrow_type; 404 SystemTrayBubbleBorder::ArrowType arrow_type;
386 if (anchor_type_ == ANCHOR_TYPE_TRAY) 405 if (anchor_type_ == ANCHOR_TYPE_TRAY)
387 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM; 406 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM;
388 else 407 else
389 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_NONE; 408 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_NONE;
390 bubble_view_->SetBubbleBorder( 409
391 new SystemTrayBubbleBorder(bubble_view_, arrow_type)); 410 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder(
411 bubble_view_, arrow_type, init_params.arrow_offset);
412 bubble_view_->SetBubbleBorder(bubble_border);
392 413
393 bubble_widget_->AddObserver(this); 414 bubble_widget_->AddObserver(this);
394 415
395 // Setup animation. 416 // Setup animation.
396 ash::SetWindowVisibilityAnimationType( 417 ash::SetWindowVisibilityAnimationType(
397 bubble_widget_->GetNativeWindow(), 418 bubble_widget_->GetNativeWindow(),
398 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 419 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
399 ash::SetWindowVisibilityAnimationTransition( 420 ash::SetWindowVisibilityAnimationTransition(
400 bubble_widget_->GetNativeWindow(), 421 bubble_widget_->GetNativeWindow(),
401 ash::ANIMATE_BOTH); 422 ash::ANIMATE_BOTH);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, 518 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget,
498 bool visible) { 519 bool visible) {
499 if (!visible) 520 if (!visible)
500 MessageLoopForUI::current()->RemoveObserver(this); 521 MessageLoopForUI::current()->RemoveObserver(this);
501 else 522 else
502 MessageLoopForUI::current()->AddObserver(this); 523 MessageLoopForUI::current()->AddObserver(this);
503 } 524 }
504 525
505 } // namespace internal 526 } // namespace internal
506 } // namespace ash 527 } // namespace ash
OLDNEW
« ash/system/tray/system_tray.cc ('K') | « ash/system/tray/system_tray_bubble.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698