OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/notifications/balloon_view.h" | 5 #include "chrome/browser/chromeos/notifications/balloon_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/models/simple_menu_model.h" | 27 #include "ui/base/models/simple_menu_model.h" |
28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 #include "views/background.h" | 29 #include "views/background.h" |
30 #include "views/controls/button/button.h" | 30 #include "views/controls/button/button.h" |
31 #include "views/controls/button/image_button.h" | 31 #include "views/controls/button/image_button.h" |
32 #include "views/controls/button/menu_button.h" | 32 #include "views/controls/button/menu_button.h" |
33 #include "views/controls/label.h" | 33 #include "views/controls/label.h" |
34 #include "views/controls/menu/menu_2.h" | 34 #include "views/controls/menu/menu_item_view.h" |
35 #include "views/controls/menu/menu_model_adapter.h" | |
35 #include "views/controls/menu/view_menu_delegate.h" | 36 #include "views/controls/menu/view_menu_delegate.h" |
36 #include "views/widget/widget.h" | 37 #include "views/widget/widget.h" |
37 | 38 |
38 namespace { | 39 namespace { |
39 // Menu commands | 40 // Menu commands |
40 const int kNoopCommand = 0; | 41 const int kNoopCommand = 0; |
41 const int kRevokePermissionCommand = 1; | 42 const int kRevokePermissionCommand = 1; |
42 | 43 |
43 // Vertical margin between close button and menu button. | 44 // Vertical margin between close button and menu button. |
44 const int kControlButtonsMargin = 6; | 45 const int kControlButtonsMargin = 6; |
45 | 46 |
46 // Top, Right margin for notification control view. | 47 // Top, Right margin for notification control view. |
47 const int kControlViewTopMargin = 4; | 48 const int kControlViewTopMargin = 4; |
48 const int kControlViewRightMargin = 6; | 49 const int kControlViewRightMargin = 6; |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 namespace chromeos { | 52 namespace chromeos { |
52 | 53 |
53 // NotificationControlView has close and menu buttons and | 54 // NotificationControlView has close and menu buttons and |
54 // overlays on top of renderer view. | 55 // overlays on top of renderer view. |
55 class NotificationControlView : public views::View, | 56 class NotificationControlView : public views::View, |
56 public views::ViewMenuDelegate, | 57 public views::ViewMenuDelegate, |
57 public ui::SimpleMenuModel::Delegate, | 58 public ui::SimpleMenuModel::Delegate, |
58 public views::ButtonListener { | 59 public views::ButtonListener { |
59 public: | 60 public: |
60 explicit NotificationControlView(BalloonViewImpl* view) | 61 explicit NotificationControlView(BalloonViewImpl* view) |
61 : balloon_view_(view), | 62 : balloon_view_(view), |
62 close_button_(NULL), | 63 close_button_(NULL), |
63 options_menu_contents_(NULL), | 64 options_menu_contents_(NULL), |
64 options_menu_menu_(NULL), | |
65 options_menu_button_(NULL) { | 65 options_menu_button_(NULL) { |
66 // TODO(oshima): make background transparent. | 66 // TODO(oshima): make background transparent. |
67 set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); | 67 set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); |
68 | 68 |
69 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 69 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
70 | 70 |
71 SkBitmap* close_button_n = rb.GetBitmapNamed(IDR_TAB_CLOSE); | 71 SkBitmap* close_button_n = rb.GetBitmapNamed(IDR_TAB_CLOSE); |
72 SkBitmap* close_button_m = rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK); | 72 SkBitmap* close_button_m = rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK); |
73 SkBitmap* close_button_h = rb.GetBitmapNamed(IDR_TAB_CLOSE_H); | 73 SkBitmap* close_button_h = rb.GetBitmapNamed(IDR_TAB_CLOSE_H); |
74 SkBitmap* close_button_p = rb.GetBitmapNamed(IDR_TAB_CLOSE_P); | 74 SkBitmap* close_button_p = rb.GetBitmapNamed(IDR_TAB_CLOSE_P); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 110 |
111 virtual gfx::Size GetPreferredSize() { | 111 virtual gfx::Size GetPreferredSize() { |
112 gfx::Rect total_bounds = | 112 gfx::Rect total_bounds = |
113 close_button_->bounds().Union(options_menu_button_->bounds()); | 113 close_button_->bounds().Union(options_menu_button_->bounds()); |
114 return total_bounds.size(); | 114 return total_bounds.size(); |
115 } | 115 } |
116 | 116 |
117 // views::ViewMenuDelegate implements. | 117 // views::ViewMenuDelegate implements. |
118 virtual void RunMenu(views::View* source, const gfx::Point& pt) { | 118 virtual void RunMenu(views::View* source, const gfx::Point& pt) { |
119 CreateOptionsMenu(); | 119 CreateOptionsMenu(); |
120 options_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 120 |
121 views::MenuModelAdapter menu_model_adapter(options_menu_contents_.get()); | |
122 views::MenuItemView menu(&menu_model_adapter); | |
123 menu_model_adapter.BuildMenu(&menu); | |
oshima
2011/07/06 18:10:36
I felt this API a bit wired because you create men
rhashimoto
2011/07/06 18:27:33
I agree that it is a little strange. The model se
| |
124 | |
125 gfx::Point screen_location; | |
126 views::View::ConvertPointToScreen(options_menu_button_, | |
127 &screen_location); | |
128 gfx::NativeWindow window = | |
129 source->GetWidget()->GetTopLevelWidget()->GetNativeWindow(); | |
130 menu.RunMenuAt(window, | |
131 options_menu_button_, | |
132 gfx::Rect(screen_location, options_menu_button_->size()), | |
133 views::MenuItemView::TOPRIGHT, | |
134 true); | |
121 } | 135 } |
122 | 136 |
123 // views::ButtonListener implements. | 137 // views::ButtonListener implements. |
124 virtual void ButtonPressed(views::Button* sender, const views::Event&) { | 138 virtual void ButtonPressed(views::Button* sender, const views::Event&) { |
125 balloon_view_->Close(true); | 139 balloon_view_->Close(true); |
126 } | 140 } |
127 | 141 |
128 // ui::SimpleMenuModel::Delegate impglements. | 142 // ui::SimpleMenuModel::Delegate impglements. |
129 virtual bool IsCommandIdChecked(int /* command_id */) const { | 143 virtual bool IsCommandIdChecked(int /* command_id */) const { |
130 // Nothing in the menu is checked. | 144 // Nothing in the menu is checked. |
(...skipping 29 matching lines...) Expand all Loading... | |
160 balloon_view_->balloon_->notification().display_source()); | 174 balloon_view_->balloon_->notification().display_source()); |
161 const string16 label_text = l10n_util::GetStringFUTF16( | 175 const string16 label_text = l10n_util::GetStringFUTF16( |
162 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, | 176 IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE, |
163 balloon_view_->balloon_->notification().display_source()); | 177 balloon_view_->balloon_->notification().display_source()); |
164 | 178 |
165 options_menu_contents_.reset(new ui::SimpleMenuModel(this)); | 179 options_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
166 // TODO(oshima): Showing the source info in the menu for now. | 180 // TODO(oshima): Showing the source info in the menu for now. |
167 // Figure out where to show the source info. | 181 // Figure out where to show the source info. |
168 options_menu_contents_->AddItem(kNoopCommand, source_label_text); | 182 options_menu_contents_->AddItem(kNoopCommand, source_label_text); |
169 options_menu_contents_->AddItem(kRevokePermissionCommand, label_text); | 183 options_menu_contents_->AddItem(kRevokePermissionCommand, label_text); |
170 | |
171 options_menu_menu_.reset(new views::Menu2(options_menu_contents_.get())); | |
172 } | 184 } |
173 | 185 |
174 BalloonViewImpl* balloon_view_; | 186 BalloonViewImpl* balloon_view_; |
175 | 187 |
176 views::ImageButton* close_button_; | 188 views::ImageButton* close_button_; |
177 | 189 |
178 // The options menu. | 190 // The options menu. |
179 scoped_ptr<ui::SimpleMenuModel> options_menu_contents_; | 191 scoped_ptr<ui::SimpleMenuModel> options_menu_contents_; |
180 scoped_ptr<views::Menu2> options_menu_menu_; | |
181 views::MenuButton* options_menu_button_; | 192 views::MenuButton* options_menu_button_; |
182 | 193 |
183 DISALLOW_COPY_AND_ASSIGN(NotificationControlView); | 194 DISALLOW_COPY_AND_ASSIGN(NotificationControlView); |
184 }; | 195 }; |
185 | 196 |
186 BalloonViewImpl::BalloonViewImpl(bool sticky, bool controls, bool web_ui) | 197 BalloonViewImpl::BalloonViewImpl(bool sticky, bool controls, bool web_ui) |
187 : balloon_(NULL), | 198 : balloon_(NULL), |
188 html_contents_(NULL), | 199 html_contents_(NULL), |
189 method_factory_(this), | 200 method_factory_(this), |
190 stale_(false), | 201 stale_(false), |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 service->DenyPermission(balloon_->notification().origin_url()); | 356 service->DenyPermission(balloon_->notification().origin_url()); |
346 } | 357 } |
347 | 358 |
348 gfx::NativeView BalloonViewImpl::GetParentNativeView() { | 359 gfx::NativeView BalloonViewImpl::GetParentNativeView() { |
349 RenderWidgetHostView* view = html_contents_->render_view_host()->view(); | 360 RenderWidgetHostView* view = html_contents_->render_view_host()->view(); |
350 DCHECK(view); | 361 DCHECK(view); |
351 return view->GetNativeView(); | 362 return view->GetNativeView(); |
352 } | 363 } |
353 | 364 |
354 } // namespace chromeos | 365 } // namespace chromeos |
OLD | NEW |