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

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

Issue 195283003: Adds a hide button to the desktop capture notification bar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/screen_capture_notification_ui.h" 5 #include "chrome/browser/ui/screen_capture_notification_ui.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "chrome/app/chrome_dll_resource.h" 8 #include "chrome/app/chrome_dll_resource.h"
9 #include "chrome/browser/ui/views/chrome_views_export.h" 9 #include "chrome/browser/ui/views/chrome_views_export.h"
10 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 #include "ui/aura/window_event_dispatcher.h" 12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/base/hit_test.h" 13 #include "ui/base/hit_test.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/views/bubble/bubble_border.h" 16 #include "ui/views/bubble/bubble_border.h"
17 #include "ui/views/bubble/bubble_frame_view.h" 17 #include "ui/views/bubble/bubble_frame_view.h"
18 #include "ui/views/controls/button/blue_button.h" 18 #include "ui/views/controls/button/blue_button.h"
19 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/link.h"
21 #include "ui/views/controls/link_listener.h"
20 #include "ui/views/corewm/shadow_types.h" 22 #include "ui/views/corewm/shadow_types.h"
21 #include "ui/views/layout/box_layout.h" 23 #include "ui/views/layout/box_layout.h"
22 #include "ui/views/view.h" 24 #include "ui/views/view.h"
23 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
24 #include "ui/views/widget/widget_delegate.h" 26 #include "ui/views/widget/widget_delegate.h"
25 27
26 namespace { 28 namespace {
27 29
28 const int kMinimumWidth = 460; 30 const int kMinimumWidth = 460;
29 const int kMaximumWidth = 1000; 31 const int kMaximumWidth = 1000;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 66
65 DISALLOW_COPY_AND_ASSIGN(NotificationBarClientView); 67 DISALLOW_COPY_AND_ASSIGN(NotificationBarClientView);
66 }; 68 };
67 69
68 } // namespace 70 } // namespace
69 71
70 // ScreenCaptureNotificationUI implementation using Views. 72 // ScreenCaptureNotificationUI implementation using Views.
71 class ScreenCaptureNotificationUIViews 73 class ScreenCaptureNotificationUIViews
72 : public ScreenCaptureNotificationUI, 74 : public ScreenCaptureNotificationUI,
73 public views::WidgetDelegateView, 75 public views::WidgetDelegateView,
74 public views::ButtonListener { 76 public views::ButtonListener,
77 public views::LinkListener {
75 public: 78 public:
76 explicit ScreenCaptureNotificationUIViews(const base::string16& text); 79 explicit ScreenCaptureNotificationUIViews(const base::string16& text);
77 virtual ~ScreenCaptureNotificationUIViews(); 80 virtual ~ScreenCaptureNotificationUIViews();
78 81
79 // ScreenCaptureNotificationUI interface. 82 // ScreenCaptureNotificationUI interface.
80 virtual void OnStarted(const base::Closure& stop_callback) OVERRIDE; 83 virtual void OnStarted(const base::Closure& stop_callback) OVERRIDE;
81 84
82 // views::View overrides. 85 // views::View overrides.
83 virtual gfx::Size GetPreferredSize() OVERRIDE; 86 virtual gfx::Size GetPreferredSize() OVERRIDE;
84 virtual void Layout() OVERRIDE; 87 virtual void Layout() OVERRIDE;
85 88
86 // views::WidgetDelegateView overrides. 89 // views::WidgetDelegateView overrides.
87 virtual void DeleteDelegate() OVERRIDE; 90 virtual void DeleteDelegate() OVERRIDE;
88 virtual views::View* GetContentsView() OVERRIDE; 91 virtual views::View* GetContentsView() OVERRIDE;
89 virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE; 92 virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
90 virtual views::NonClientFrameView* CreateNonClientFrameView( 93 virtual views::NonClientFrameView* CreateNonClientFrameView(
91 views::Widget* widget) OVERRIDE; 94 views::Widget* widget) OVERRIDE;
92 virtual base::string16 GetWindowTitle() const OVERRIDE; 95 virtual base::string16 GetWindowTitle() const OVERRIDE;
93 virtual bool ShouldShowWindowTitle() const OVERRIDE; 96 virtual bool ShouldShowWindowTitle() const OVERRIDE;
94 virtual bool ShouldShowCloseButton() const OVERRIDE; 97 virtual bool ShouldShowCloseButton() const OVERRIDE;
95 98
96 // views::ButtonListener interface. 99 // views::ButtonListener interface.
97 virtual void ButtonPressed(views::Button* sender, 100 virtual void ButtonPressed(views::Button* sender,
98 const ui::Event& event) OVERRIDE; 101 const ui::Event& event) OVERRIDE;
99 102
103 // views::LinkListener interface.
104 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
105
100 private: 106 private:
101 // Helper to call |stop_callback_|. 107 // Helper to call |stop_callback_|.
102 void NotifyStopped(); 108 void NotifyStopped();
103 109
104 const base::string16 text_; 110 const base::string16 text_;
105 base::Closure stop_callback_; 111 base::Closure stop_callback_;
106 NotificationBarClientView* client_view_; 112 NotificationBarClientView* client_view_;
107 views::ImageView* gripper_; 113 views::ImageView* gripper_;
108 views::Label* label_; 114 views::Label* label_;
109 views::BlueButton* stop_button_; 115 views::BlueButton* stop_button_;
116 views::Link* hide_link_;
110 117
111 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIViews); 118 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIViews);
112 }; 119 };
113 120
114 ScreenCaptureNotificationUIViews::ScreenCaptureNotificationUIViews( 121 ScreenCaptureNotificationUIViews::ScreenCaptureNotificationUIViews(
115 const base::string16& text) 122 const base::string16& text)
116 : text_(text), 123 : text_(text),
117 client_view_(NULL), 124 client_view_(NULL),
118 gripper_(NULL), 125 gripper_(NULL),
119 label_(NULL), 126 label_(NULL),
120 stop_button_(NULL) { 127 stop_button_(NULL),
128 hide_link_(NULL) {
121 set_owned_by_client(); 129 set_owned_by_client();
122 130
123 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> 131 set_background(views::Background::CreateSolidBackground(GetNativeTheme()->
124 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); 132 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)));
125 133
126 gripper_ = new views::ImageView(); 134 gripper_ = new views::ImageView();
127 gripper_->SetImage( 135 gripper_->SetImage(
128 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 136 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
129 IDR_SCREEN_CAPTURE_NOTIFICATION_GRIP)); 137 IDR_SCREEN_CAPTURE_NOTIFICATION_GRIP));
130 AddChildView(gripper_); 138 AddChildView(gripper_);
131 139
132 label_ = new views::Label(); 140 label_ = new views::Label();
133 AddChildView(label_); 141 AddChildView(label_);
134 142
135 base::string16 stop_text = 143 base::string16 stop_text =
136 l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP); 144 l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP);
137 stop_button_ = new views::BlueButton(this, stop_text); 145 stop_button_ = new views::BlueButton(this, stop_text);
138 AddChildView(stop_button_); 146 AddChildView(stop_button_);
147
148 hide_link_ = new views::Link(
149 l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_HIDE));
150 hide_link_->set_listener(this);
151 AddChildView(hide_link_);
139 } 152 }
140 153
141 ScreenCaptureNotificationUIViews::~ScreenCaptureNotificationUIViews() { 154 ScreenCaptureNotificationUIViews::~ScreenCaptureNotificationUIViews() {
142 stop_callback_.Reset(); 155 stop_callback_.Reset();
143 delete GetWidget(); 156 delete GetWidget();
144 } 157 }
145 158
146 void ScreenCaptureNotificationUIViews::OnStarted( 159 void ScreenCaptureNotificationUIViews::OnStarted(
147 const base::Closure& stop_callback) { 160 const base::Closure& stop_callback) {
148 stop_callback_ = stop_callback; 161 stop_callback_ = stop_callback;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 work_area.y() + work_area.height() - size.height(), 199 work_area.y() + work_area.height() - size.height(),
187 size.width(), size.height()); 200 size.width(), size.height());
188 widget->SetBounds(bounds); 201 widget->SetBounds(bounds);
189 202
190 widget->Show(); 203 widget->Show();
191 } 204 }
192 205
193 gfx::Size ScreenCaptureNotificationUIViews::GetPreferredSize() { 206 gfx::Size ScreenCaptureNotificationUIViews::GetPreferredSize() {
194 gfx::Size grip_size = gripper_->GetPreferredSize(); 207 gfx::Size grip_size = gripper_->GetPreferredSize();
195 gfx::Size label_size = child_at(1)->GetPreferredSize(); 208 gfx::Size label_size = child_at(1)->GetPreferredSize();
196 gfx::Size button_size = child_at(2)->GetPreferredSize(); 209 gfx::Size stop_button_size = child_at(2)->GetPreferredSize();
197 int width = kHorizontalMargin * 2 + grip_size.width() + label_size.width() + 210 gfx::Size hide_link_size = child_at(3)->GetPreferredSize();
Sergey Ulanov 2014/03/11 23:45:38 Please replace child_at(?) here with label_, stop_
jiayl 2014/03/11 23:54:35 Done.
198 button_size.width(); 211 int width = kHorizontalMargin * 3 + grip_size.width() + label_size.width() +
212 stop_button_size.width() + hide_link_size.width();
199 width = std::max(width, kMinimumWidth); 213 width = std::max(width, kMinimumWidth);
200 width = std::min(width, kMaximumWidth); 214 width = std::min(width, kMaximumWidth);
201 return gfx::Size(width, std::max(label_size.height(), button_size.height())); 215 return gfx::Size(width, std::max(label_size.height(),
216 std::max(hide_link_size.height(),
217 stop_button_size.height())));
202 } 218 }
203 219
204 void ScreenCaptureNotificationUIViews::Layout() { 220 void ScreenCaptureNotificationUIViews::Layout() {
205 gfx::Rect grip_rect(gripper_->GetPreferredSize()); 221 gfx::Rect grip_rect(gripper_->GetPreferredSize());
206 grip_rect.set_y(bounds().height() / 2 - grip_rect.height() / 2); 222 grip_rect.set_y(bounds().height() / 2 - grip_rect.height() / 2);
207 gripper_->SetBoundsRect(grip_rect); 223 gripper_->SetBoundsRect(grip_rect);
208 224
209 gfx::Rect button_rect(stop_button_->GetPreferredSize()); 225 gfx::Rect stop_button_rect(stop_button_->GetPreferredSize());
210 button_rect.set_x(bounds().width() - button_rect.width()); 226 gfx::Rect hide_link_rect(hide_link_->GetPreferredSize());
211 stop_button_->SetBoundsRect(button_rect);
212 227
213 gfx::Rect label_rect; 228 stop_button_rect.set_x(bounds().width() - stop_button_rect.width() -
229 kHorizontalMargin - hide_link_rect.width());
230 stop_button_->SetBoundsRect(stop_button_rect);
231
232 hide_link_rect.set_x(stop_button_rect.right() + kHorizontalMargin);
233 hide_link_rect.set_y((bounds().height() - hide_link_rect.height()) / 2);
234 hide_link_->SetBoundsRect(hide_link_rect);
235
236 gfx::Rect label_rect(label_->GetPreferredSize());
214 label_rect.set_x(grip_rect.right() + kHorizontalMargin); 237 label_rect.set_x(grip_rect.right() + kHorizontalMargin);
215 label_rect.set_width(button_rect.x() - kHorizontalMargin - label_rect.x()); 238 label_rect.set_width(
239 stop_button_rect.x() - kHorizontalMargin - label_rect.x());
216 label_rect.set_height(bounds().height()); 240 label_rect.set_height(bounds().height());
217 label_->SetBoundsRect(label_rect); 241 label_->SetBoundsRect(label_rect);
218 242
219 client_view_->SetClientRect(button_rect); 243 client_view_->SetClientRect(gfx::Rect(
244 stop_button_rect.x(), stop_button_rect.y(),
245 stop_button_rect.width() + kHorizontalMargin + hide_link_rect.width(),
246 std::max(stop_button_rect.height(), hide_link_rect.height())));
220 } 247 }
221 248
222 void ScreenCaptureNotificationUIViews::DeleteDelegate() { 249 void ScreenCaptureNotificationUIViews::DeleteDelegate() {
223 NotifyStopped(); 250 NotifyStopped();
224 } 251 }
225 252
226 views::View* ScreenCaptureNotificationUIViews::GetContentsView() { 253 views::View* ScreenCaptureNotificationUIViews::GetContentsView() {
227 return this; 254 return this;
228 } 255 }
229 256
(...skipping 28 matching lines...) Expand all
258 285
259 bool ScreenCaptureNotificationUIViews::ShouldShowCloseButton() const { 286 bool ScreenCaptureNotificationUIViews::ShouldShowCloseButton() const {
260 return false; 287 return false;
261 } 288 }
262 289
263 void ScreenCaptureNotificationUIViews::ButtonPressed(views::Button* sender, 290 void ScreenCaptureNotificationUIViews::ButtonPressed(views::Button* sender,
264 const ui::Event& event) { 291 const ui::Event& event) {
265 NotifyStopped(); 292 NotifyStopped();
266 } 293 }
267 294
295 void ScreenCaptureNotificationUIViews::LinkClicked(
296 views::Link* source, int event_flags) {
297 GetWidget()->Minimize();
Sergey Ulanov 2014/03/11 23:45:38 Does this work as expected on Windows and Linux? N
jiayl 2014/03/11 23:54:35 It works as expected on Linux because the notifica
jiayl 2014/03/12 01:12:49 Fixed now. Confirmed working on Linux/Windows/Mac.
298 }
299
268 void ScreenCaptureNotificationUIViews::NotifyStopped() { 300 void ScreenCaptureNotificationUIViews::NotifyStopped() {
269 if (!stop_callback_.is_null()) { 301 if (!stop_callback_.is_null()) {
270 base::Closure callback = stop_callback_; 302 base::Closure callback = stop_callback_;
271 stop_callback_.Reset(); 303 stop_callback_.Reset();
272 callback.Run(); 304 callback.Run();
273 } 305 }
274 } 306 }
275 307
276 } // namespace 308 } // namespace
277 309
278 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create( 310 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create(
279 const base::string16& text) { 311 const base::string16& text) {
280 return scoped_ptr<ScreenCaptureNotificationUI>( 312 return scoped_ptr<ScreenCaptureNotificationUI>(
281 new ScreenCaptureNotificationUIViews(text)); 313 new ScreenCaptureNotificationUIViews(text));
282 } 314 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698