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

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: sync 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/layout/box_layout.h" 20 #include "ui/views/controls/link.h"
21 #include "ui/views/controls/link_listener.h"
21 #include "ui/views/view.h" 22 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h" 24 #include "ui/views/widget/widget_delegate.h"
24 #include "ui/wm/core/shadow_types.h" 25 #include "ui/wm/core/shadow_types.h"
25 26
26 namespace { 27 namespace {
27 28
28 const int kMinimumWidth = 460; 29 const int kMinimumWidth = 460;
29 const int kMaximumWidth = 1000; 30 const int kMaximumWidth = 1000;
30 const int kHorizontalMargin = 10; 31 const int kHorizontalMargin = 10;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 65
65 DISALLOW_COPY_AND_ASSIGN(NotificationBarClientView); 66 DISALLOW_COPY_AND_ASSIGN(NotificationBarClientView);
66 }; 67 };
67 68
68 } // namespace 69 } // namespace
69 70
70 // ScreenCaptureNotificationUI implementation using Views. 71 // ScreenCaptureNotificationUI implementation using Views.
71 class ScreenCaptureNotificationUIViews 72 class ScreenCaptureNotificationUIViews
72 : public ScreenCaptureNotificationUI, 73 : public ScreenCaptureNotificationUI,
73 public views::WidgetDelegateView, 74 public views::WidgetDelegateView,
74 public views::ButtonListener { 75 public views::ButtonListener,
76 public views::LinkListener {
75 public: 77 public:
76 explicit ScreenCaptureNotificationUIViews(const base::string16& text); 78 explicit ScreenCaptureNotificationUIViews(const base::string16& text);
77 virtual ~ScreenCaptureNotificationUIViews(); 79 virtual ~ScreenCaptureNotificationUIViews();
78 80
79 // ScreenCaptureNotificationUI interface. 81 // ScreenCaptureNotificationUI interface.
80 virtual void OnStarted(const base::Closure& stop_callback) OVERRIDE; 82 virtual void OnStarted(const base::Closure& stop_callback) OVERRIDE;
81 83
82 // views::View overrides. 84 // views::View overrides.
83 virtual gfx::Size GetPreferredSize() OVERRIDE; 85 virtual gfx::Size GetPreferredSize() OVERRIDE;
84 virtual void Layout() OVERRIDE; 86 virtual void Layout() OVERRIDE;
85 87
86 // views::WidgetDelegateView overrides. 88 // views::WidgetDelegateView overrides.
87 virtual void DeleteDelegate() OVERRIDE; 89 virtual void DeleteDelegate() OVERRIDE;
88 virtual views::View* GetContentsView() OVERRIDE; 90 virtual views::View* GetContentsView() OVERRIDE;
89 virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE; 91 virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
90 virtual views::NonClientFrameView* CreateNonClientFrameView( 92 virtual views::NonClientFrameView* CreateNonClientFrameView(
91 views::Widget* widget) OVERRIDE; 93 views::Widget* widget) OVERRIDE;
92 virtual base::string16 GetWindowTitle() const OVERRIDE; 94 virtual base::string16 GetWindowTitle() const OVERRIDE;
93 virtual bool ShouldShowWindowTitle() const OVERRIDE; 95 virtual bool ShouldShowWindowTitle() const OVERRIDE;
94 virtual bool ShouldShowCloseButton() const OVERRIDE; 96 virtual bool ShouldShowCloseButton() const OVERRIDE;
97 virtual bool CanActivate() 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 // TODO(jiayl): IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON is used for the need to
149 // merge to M34. Change it to a new IDS_ after the merge.
150 hide_link_ = new views::Link(
151 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON));
152 hide_link_->set_listener(this);
153 AddChildView(hide_link_);
139 } 154 }
140 155
141 ScreenCaptureNotificationUIViews::~ScreenCaptureNotificationUIViews() { 156 ScreenCaptureNotificationUIViews::~ScreenCaptureNotificationUIViews() {
142 stop_callback_.Reset(); 157 stop_callback_.Reset();
143 delete GetWidget(); 158 delete GetWidget();
144 } 159 }
145 160
146 void ScreenCaptureNotificationUIViews::OnStarted( 161 void ScreenCaptureNotificationUIViews::OnStarted(
147 const base::Closure& stop_callback) { 162 const base::Closure& stop_callback) {
148 stop_callback_ = stop_callback; 163 stop_callback_ = stop_callback;
149 164
150 label_->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE); 165 label_->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE);
151 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 166 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
152 label_->SetText(text_); 167 label_->SetText(text_);
153 168
154 views::Widget* widget = new views::Widget; 169 views::Widget* widget = new views::Widget;
155 170
156 views::Widget::InitParams params; 171 views::Widget::InitParams params;
157 params.delegate = this; 172 params.delegate = this;
158 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 173 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
159 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 174 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
160 params.remove_standard_frame = true; 175 params.remove_standard_frame = true;
161 params.keep_on_top = true; 176 params.keep_on_top = true;
162 params.top_level = true; 177 params.top_level = true;
163 params.can_activate = false; 178 // Make sure can_activate is true so the window icon will show in the taskbar.
179 params.can_activate = true;
164 180
165 #if defined(USE_ASH) 181 #if defined(USE_ASH)
166 // TODO(sergeyu): The notification bar must be shown on the monitor that's 182 // TODO(sergeyu): The notification bar must be shown on the monitor that's
167 // being captured. Make sure it's always the case. Currently we always capture 183 // being captured. Make sure it's always the case. Currently we always capture
168 // the primary monitor. 184 // the primary monitor.
169 if (ash::Shell::HasInstance()) 185 if (ash::Shell::HasInstance())
170 params.context = ash::Shell::GetPrimaryRootWindow(); 186 params.context = ash::Shell::GetPrimaryRootWindow();
171 #endif 187 #endif
172 188
173 widget->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 189 widget->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
(...skipping 11 matching lines...) Expand all
185 work_area.x() + work_area.width() / 2 - size.width() / 2, 201 work_area.x() + work_area.width() / 2 - size.width() / 2,
186 work_area.y() + work_area.height() - size.height(), 202 work_area.y() + work_area.height() - size.height(),
187 size.width(), size.height()); 203 size.width(), size.height());
188 widget->SetBounds(bounds); 204 widget->SetBounds(bounds);
189 205
190 widget->Show(); 206 widget->Show();
191 } 207 }
192 208
193 gfx::Size ScreenCaptureNotificationUIViews::GetPreferredSize() { 209 gfx::Size ScreenCaptureNotificationUIViews::GetPreferredSize() {
194 gfx::Size grip_size = gripper_->GetPreferredSize(); 210 gfx::Size grip_size = gripper_->GetPreferredSize();
195 gfx::Size label_size = child_at(1)->GetPreferredSize(); 211 gfx::Size label_size = label_->GetPreferredSize();
196 gfx::Size button_size = child_at(2)->GetPreferredSize(); 212 gfx::Size stop_button_size = stop_button_->GetPreferredSize();
197 int width = kHorizontalMargin * 2 + grip_size.width() + label_size.width() + 213 gfx::Size hide_link_size = hide_link_->GetPreferredSize();
198 button_size.width(); 214 int width = kHorizontalMargin * 3 + grip_size.width() + label_size.width() +
215 stop_button_size.width() + hide_link_size.width();
199 width = std::max(width, kMinimumWidth); 216 width = std::max(width, kMinimumWidth);
200 width = std::min(width, kMaximumWidth); 217 width = std::min(width, kMaximumWidth);
201 return gfx::Size(width, std::max(label_size.height(), button_size.height())); 218 return gfx::Size(width, std::max(label_size.height(),
219 std::max(hide_link_size.height(),
220 stop_button_size.height())));
202 } 221 }
203 222
204 void ScreenCaptureNotificationUIViews::Layout() { 223 void ScreenCaptureNotificationUIViews::Layout() {
205 gfx::Rect grip_rect(gripper_->GetPreferredSize()); 224 gfx::Rect grip_rect(gripper_->GetPreferredSize());
206 grip_rect.set_y(bounds().height() / 2 - grip_rect.height() / 2); 225 grip_rect.set_y((bounds().height() - grip_rect.height()) / 2);
207 gripper_->SetBoundsRect(grip_rect); 226 gripper_->SetBoundsRect(grip_rect);
208 227
209 gfx::Rect button_rect(stop_button_->GetPreferredSize()); 228 gfx::Rect stop_button_rect(stop_button_->GetPreferredSize());
210 button_rect.set_x(bounds().width() - button_rect.width()); 229 gfx::Rect hide_link_rect(hide_link_->GetPreferredSize());
211 stop_button_->SetBoundsRect(button_rect); 230
231 hide_link_rect.set_x(bounds().width() - hide_link_rect.width());
232 hide_link_rect.set_y((bounds().height() - hide_link_rect.height()) / 2);
233 hide_link_->SetBoundsRect(hide_link_rect);
234
235 stop_button_rect.set_x(
236 hide_link_rect.x() - kHorizontalMargin - stop_button_rect.width());
237 stop_button_->SetBoundsRect(stop_button_rect);
212 238
213 gfx::Rect label_rect; 239 gfx::Rect label_rect;
214 label_rect.set_x(grip_rect.right() + kHorizontalMargin); 240 label_rect.set_x(grip_rect.right() + kHorizontalMargin);
215 label_rect.set_width(button_rect.x() - kHorizontalMargin - label_rect.x()); 241 label_rect.set_width(
242 stop_button_rect.x() - kHorizontalMargin - label_rect.x());
216 label_rect.set_height(bounds().height()); 243 label_rect.set_height(bounds().height());
217 label_->SetBoundsRect(label_rect); 244 label_->SetBoundsRect(label_rect);
218 245
219 client_view_->SetClientRect(button_rect); 246 client_view_->SetClientRect(gfx::Rect(
247 stop_button_rect.x(), stop_button_rect.y(),
248 stop_button_rect.width() + kHorizontalMargin + hide_link_rect.width(),
249 std::max(stop_button_rect.height(), hide_link_rect.height())));
220 } 250 }
221 251
222 void ScreenCaptureNotificationUIViews::DeleteDelegate() { 252 void ScreenCaptureNotificationUIViews::DeleteDelegate() {
223 NotifyStopped(); 253 NotifyStopped();
224 } 254 }
225 255
226 views::View* ScreenCaptureNotificationUIViews::GetContentsView() { 256 views::View* ScreenCaptureNotificationUIViews::GetContentsView() {
227 return this; 257 return this;
228 } 258 }
229 259
(...skipping 23 matching lines...) Expand all
253 } 283 }
254 284
255 bool ScreenCaptureNotificationUIViews::ShouldShowWindowTitle() const { 285 bool ScreenCaptureNotificationUIViews::ShouldShowWindowTitle() const {
256 return false; 286 return false;
257 } 287 }
258 288
259 bool ScreenCaptureNotificationUIViews::ShouldShowCloseButton() const { 289 bool ScreenCaptureNotificationUIViews::ShouldShowCloseButton() const {
260 return false; 290 return false;
261 } 291 }
262 292
293 bool ScreenCaptureNotificationUIViews::CanActivate() const {
294 // If we do not override this method, the window sometimes does not properly
295 // restore to its normal size on Windows.
296 return false;
297 }
298
263 void ScreenCaptureNotificationUIViews::ButtonPressed(views::Button* sender, 299 void ScreenCaptureNotificationUIViews::ButtonPressed(views::Button* sender,
264 const ui::Event& event) { 300 const ui::Event& event) {
265 NotifyStopped(); 301 NotifyStopped();
266 } 302 }
267 303
304 void ScreenCaptureNotificationUIViews::LinkClicked(views::Link* source,
305 int event_flags) {
306 GetWidget()->Minimize();
307 }
308
268 void ScreenCaptureNotificationUIViews::NotifyStopped() { 309 void ScreenCaptureNotificationUIViews::NotifyStopped() {
269 if (!stop_callback_.is_null()) { 310 if (!stop_callback_.is_null()) {
270 base::Closure callback = stop_callback_; 311 base::Closure callback = stop_callback_;
271 stop_callback_.Reset(); 312 stop_callback_.Reset();
272 callback.Run(); 313 callback.Run();
273 } 314 }
274 } 315 }
275 316
276 } // namespace 317 } // namespace
277 318
278 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create( 319 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create(
279 const base::string16& text) { 320 const base::string16& text) {
280 return scoped_ptr<ScreenCaptureNotificationUI>( 321 return scoped_ptr<ScreenCaptureNotificationUI>(
281 new ScreenCaptureNotificationUIViews(text)); 322 new ScreenCaptureNotificationUIViews(text));
282 } 323 }
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