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

Side by Side Diff: chrome/browser/ui/views/avatar_menu_bubble_view.cc

Issue 11646008: Close avatar bubble when avatar button is clicked a second time (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 7 years, 11 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 "chrome/browser/ui/views/avatar_menu_bubble_view.h" 5 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/avatar_menu_model.h" 12 #include "chrome/browser/profiles/avatar_menu_model.h"
12 #include "chrome/browser/profiles/profile_info_cache.h" 13 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_info_util.h" 14 #include "chrome/browser/profiles/profile_info_util.h"
14 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h"
16 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/font.h" 23 #include "ui/gfx/font.h"
22 #include "ui/gfx/image/canvas_image_source.h" 24 #include "ui/gfx/image/canvas_image_source.h"
23 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
24 #include "ui/views/controls/button/custom_button.h" 26 #include "ui/views/controls/button/custom_button.h"
25 #include "ui/views/controls/button/image_button.h" 27 #include "ui/views/controls/button/image_button.h"
26 #include "ui/views/controls/image_view.h" 28 #include "ui/views/controls/image_view.h"
27 #include "ui/views/controls/label.h" 29 #include "ui/views/controls/label.h"
28 #include "ui/views/controls/link.h" 30 #include "ui/views/controls/link.h"
29 #include "ui/views/controls/separator.h" 31 #include "ui/views/controls/separator.h"
32 #include "ui/views/widget/widget.h"
30 33
31 namespace { 34 namespace {
32 35
33 const int kItemHeight = 44; 36 const int kItemHeight = 44;
34 const int kItemMarginY = 4; 37 const int kItemMarginY = 4;
35 const int kIconMarginX = 6; 38 const int kIconMarginX = 6;
36 const int kSeparatorPaddingY = 5; 39 const int kSeparatorPaddingY = 5;
37 const int kMaxItemTextWidth = 200; 40 const int kMaxItemTextWidth = 200;
38 const SkColor kHighlightColor = 0xFFE3EDF6; 41 const SkColor kHighlightColor = 0xFFE3EDF6;
39 42
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 edit_link_->state() == views::CustomButton::STATE_HOVERED || 383 edit_link_->state() == views::CustomButton::STATE_HOVERED ||
381 HasFocus() || 384 HasFocus() ||
382 edit_link_->HasFocus(); 385 edit_link_->HasFocus();
383 } 386 }
384 387
385 } // namespace 388 } // namespace
386 389
387 390
388 // AvatarMenuBubbleView ------------------------------------------------------- 391 // AvatarMenuBubbleView -------------------------------------------------------
389 392
393 // static
394 AvatarMenuBubbleView* AvatarMenuBubbleView::avatar_bubble_ = NULL;
395
396 // static
397 void AvatarMenuBubbleView::ShowBubble(
398 views::View* anchor_view,
399 views::BubbleBorder::ArrowLocation arrow_location,
400 views::BubbleBorder::BubbleAlignment border_alignment,
401 const gfx::Rect& anchor_rect,
402 Browser* browser) {
403 if (IsShowing())
404 return;
405
406 DCHECK(chrome::IsCommandEnabled(browser, IDC_SHOW_AVATAR_MENU));
407 avatar_bubble_ = new AvatarMenuBubbleView(
408 anchor_view, arrow_location, anchor_rect, browser);
409 views::BubbleDelegateView::CreateBubble(avatar_bubble_);
410 avatar_bubble_->SetAlignment(border_alignment);
411 avatar_bubble_->Show();
412 }
413
414 // static
415 bool AvatarMenuBubbleView::IsShowing() {
416 return avatar_bubble_ != NULL;
417 }
418
419 // static
420 void AvatarMenuBubbleView::Hide() {
421 if (IsShowing())
422 avatar_bubble_->GetWidget()->Close();
423 }
424
390 AvatarMenuBubbleView::AvatarMenuBubbleView( 425 AvatarMenuBubbleView::AvatarMenuBubbleView(
391 views::View* anchor_view, 426 views::View* anchor_view,
392 views::BubbleBorder::ArrowLocation arrow_location, 427 views::BubbleBorder::ArrowLocation arrow_location,
393 const gfx::Rect& anchor_rect, 428 const gfx::Rect& anchor_rect,
394 Browser* browser) 429 Browser* browser)
395 : BubbleDelegateView(anchor_view, arrow_location), 430 : BubbleDelegateView(anchor_view, arrow_location),
396 add_profile_link_(NULL), 431 add_profile_link_(NULL),
397 anchor_rect_(anchor_rect), 432 anchor_rect_(anchor_rect),
398 browser_(browser) { 433 browser_(browser) {
399 avatar_menu_model_.reset(new AvatarMenuModel( 434 avatar_menu_model_.reset(new AvatarMenuModel(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 return anchor_rect_; 548 return anchor_rect_;
514 } 549 }
515 550
516 void AvatarMenuBubbleView::Init() { 551 void AvatarMenuBubbleView::Init() {
517 // Build the menu for the first time. 552 // Build the menu for the first time.
518 OnAvatarMenuModelChanged(avatar_menu_model_.get()); 553 OnAvatarMenuModelChanged(avatar_menu_model_.get());
519 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); 554 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE));
520 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); 555 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE));
521 } 556 }
522 557
558 void AvatarMenuBubbleView::WindowClosing() {
559 DCHECK_EQ(avatar_bubble_, this);
560 avatar_bubble_ = NULL;
561 }
562
523 void AvatarMenuBubbleView::OnAvatarMenuModelChanged( 563 void AvatarMenuBubbleView::OnAvatarMenuModelChanged(
524 AvatarMenuModel* avatar_menu_model) { 564 AvatarMenuModel* avatar_menu_model) {
525 // Unset all our child view references and call RemoveAllChildViews() which 565 // Unset all our child view references and call RemoveAllChildViews() which
526 // will actually delete them. 566 // will actually delete them.
527 add_profile_link_ = NULL; 567 add_profile_link_ = NULL;
528 item_views_.clear(); 568 item_views_.clear();
529 RemoveAllChildViews(true); 569 RemoveAllChildViews(true);
530 570
531 for (size_t i = 0; i < avatar_menu_model->GetNumberOfItems(); ++i) { 571 for (size_t i = 0; i < avatar_menu_model->GetNumberOfItems(); ++i) {
532 const AvatarMenuModel::Item& item = avatar_menu_model->GetItemAt(i); 572 const AvatarMenuModel::Item& item = avatar_menu_model->GetItemAt(i);
(...skipping 13 matching lines...) Expand all
546 add_profile_link_->set_listener(this); 586 add_profile_link_->set_listener(this);
547 add_profile_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 587 add_profile_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
548 add_profile_link_->SetBackgroundColor(color()); 588 add_profile_link_->SetBackgroundColor(color());
549 AddChildView(add_profile_link_); 589 AddChildView(add_profile_link_);
550 590
551 // If the bubble has already been shown then resize and reposition the bubble. 591 // If the bubble has already been shown then resize and reposition the bubble.
552 Layout(); 592 Layout();
553 if (GetBubbleFrameView()) 593 if (GetBubbleFrameView())
554 SizeToContents(); 594 SizeToContents();
555 } 595 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_bubble_view.h ('k') | chrome/browser/ui/views/avatar_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698