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

Side by Side Diff: chrome/browser/chromeos/status/status_area_bubble.cc

Issue 10056001: chromeos: Remove old status-area related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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
(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 "chrome/browser/chromeos/status/status_area_bubble.h"
6
7 #include "chrome/browser/ui/views/window.h"
8 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "ui/views/bubble/bubble_delegate.h"
10 #include "ui/views/controls/label.h"
11 #include "ui/views/layout/box_layout.h"
12 #include "ui/views/layout/fill_layout.h"
13
14 namespace {
15
16 const size_t kCloseBubbleTimerInSec = 5;
17
18 } // namespace
19
20 namespace chromeos {
21
22 StatusAreaBubbleContentView::StatusAreaBubbleContentView(
23 views::View* icon_view,
24 const string16& message)
25 : icon_view_(icon_view),
26 message_view_(new views::Label(message)) {
27 // Padding around status.
28 const int kPadX = 10, kPadY = 5;
29 // Padding between image and text.
30 const int kTextPadX = 10;
31
32 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
33 kPadX, kPadY, kTextPadX));
34 AddChildView(icon_view_);
35 message_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
36 AddChildView(message_view_);
37 }
38
39 StatusAreaBubbleContentView::~StatusAreaBubbleContentView() {
40 }
41
42 string16 StatusAreaBubbleContentView::GetMessage() const {
43 return message_view_->text();
44 }
45
46 void StatusAreaBubbleContentView::SetMessage(const string16& message) {
47 message_view_->SetText(message);
48 }
49
50 void StatusAreaBubbleContentView::GetAccessibleState(
51 ui::AccessibleViewState* state) {
52 state->role = ui::AccessibilityTypes::ROLE_STATICTEXT;
53 state->state = ui::AccessibilityTypes::STATE_READONLY;
54 state->name = GetMessage();
55 }
56
57
58 // A BubbleDelegateView implementation to be used by StatusAreaBubbleController.
59 // This class is also responsible for handling events while
60 // StatusAreaContentView is only responsible for showing the content.
61 class StatusAreaBubbleController::StatusAreaBubbleDelegateView
62 : public views::BubbleDelegateView {
63 public:
64 explicit StatusAreaBubbleDelegateView(views::View* anchor_view)
65 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT) {
66 }
67
68 protected:
69 // views::View override
70 bool OnMousePressed(const views::MouseEvent& event) OVERRIDE {
71 // Handle mouse events to close when clicked.
72 return true;
73 }
74 // views::View override
75 void OnMouseReleased(const views::MouseEvent& event) OVERRIDE {
76 GetWidget()->Close();
77 }
78
79 private:
80 DISALLOW_COPY_AND_ASSIGN(StatusAreaBubbleDelegateView);
81 };
82
83
84 StatusAreaBubbleController::StatusAreaBubbleController()
85 : bubble_(NULL) {
86 }
87
88 StatusAreaBubbleController::~StatusAreaBubbleController() {
89 HideBubble();
90 }
91
92 // static
93 StatusAreaBubbleController* StatusAreaBubbleController::
94 ShowBubbleUnderViewForAWhile(views::View* view,
95 StatusAreaBubbleContentView* content) {
96 StatusAreaBubbleController* controller = new StatusAreaBubbleController;
97 StatusAreaBubbleDelegateView* bubble = new StatusAreaBubbleDelegateView(view);
98 bubble->SetLayoutManager(new views::FillLayout);
99 bubble->AddChildView(content);
100 controller->bubble_ = bubble;
101 bubble->set_use_focusless(true);
102 browser::CreateViewsBubbleAboveLockScreen(bubble);
103 bubble->Show();
104 controller->timer_.Start(FROM_HERE,
105 base::TimeDelta::FromSeconds(kCloseBubbleTimerInSec),
106 controller,
107 &StatusAreaBubbleController::HideBubble);
108
109 bubble->GetWidget()->AddObserver(controller);
110 return controller;
111 }
112
113 void StatusAreaBubbleController::OnWidgetClosing(views::Widget* widget) {
114 // There are two ways to close the bubble.
115 // 1. Call Widget::Close. (This way is used by the bubble implementation.)
116 // 2. Call HideBubble. (This way is used by code outside the bubble impl.)
117 // OnWidgetClosing is only called in the case of 1.
118 bubble_ = NULL;
119 }
120
121 bool StatusAreaBubbleController::IsBubbleShown() const {
122 return bubble_;
123 }
124
125 void StatusAreaBubbleController::HideBubble() {
126 if (!IsBubbleShown())
127 return;
128 timer_.Stop(); // no-op if it's not running.
129
130 // Instead of setting |bubble_| NULL in OnWidgetClosing, do it here because
131 // |this| may be deleted when OnWidgetClosing is called.
132 bubble_->GetWidget()->RemoveObserver(this);
133 bubble_->GetWidget()->Close();
134 bubble_ = NULL;
135 }
136
137 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/status_area_bubble.h ('k') | chrome/browser/chromeos/status/status_area_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698