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

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

Issue 201933003: Merge 256851 "Adds a hide button to the desktop capture notifica..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1847/src/
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 | Annotate | Revision Log
« 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/root_window.h" 12 #include "ui/aura/root_window.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;
98 virtual bool CanActivate() const OVERRIDE;
95 99
96 // views::ButtonListener interface. 100 // views::ButtonListener interface.
97 virtual void ButtonPressed(views::Button* sender, 101 virtual void ButtonPressed(views::Button* sender,
98 const ui::Event& event) OVERRIDE; 102 const ui::Event& event) OVERRIDE;
99 103
104 // views::LinkListener interface.
105 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
106
100 private: 107 private:
101 // Helper to call |stop_callback_|. 108 // Helper to call |stop_callback_|.
102 void NotifyStopped(); 109 void NotifyStopped();
103 110
104 const base::string16 text_; 111 const base::string16 text_;
105 base::Closure stop_callback_; 112 base::Closure stop_callback_;
106 NotificationBarClientView* client_view_; 113 NotificationBarClientView* client_view_;
107 views::ImageView* gripper_; 114 views::ImageView* gripper_;
108 views::Label* label_; 115 views::Label* label_;
109 views::BlueButton* stop_button_; 116 views::BlueButton* stop_button_;
117 views::Link* hide_link_;
110 118
111 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIViews); 119 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIViews);
112 }; 120 };
113 121
114 ScreenCaptureNotificationUIViews::ScreenCaptureNotificationUIViews( 122 ScreenCaptureNotificationUIViews::ScreenCaptureNotificationUIViews(
115 const base::string16& text) 123 const base::string16& text)
116 : text_(text), 124 : text_(text),
117 client_view_(NULL), 125 client_view_(NULL),
118 gripper_(NULL), 126 gripper_(NULL),
119 label_(NULL), 127 label_(NULL),
120 stop_button_(NULL) { 128 stop_button_(NULL),
129 hide_link_(NULL) {
121 set_owned_by_client(); 130 set_owned_by_client();
122 131
123 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> 132 set_background(views::Background::CreateSolidBackground(GetNativeTheme()->
124 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); 133 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)));
125 134
126 gripper_ = new views::ImageView(); 135 gripper_ = new views::ImageView();
127 gripper_->SetImage( 136 gripper_->SetImage(
128 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 137 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
129 IDR_SCREEN_CAPTURE_NOTIFICATION_GRIP)); 138 IDR_SCREEN_CAPTURE_NOTIFICATION_GRIP));
130 AddChildView(gripper_); 139 AddChildView(gripper_);
131 140
132 label_ = new views::Label(); 141 label_ = new views::Label();
133 AddChildView(label_); 142 AddChildView(label_);
134 143
135 base::string16 stop_text = 144 base::string16 stop_text =
136 l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP); 145 l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP);
137 stop_button_ = new views::BlueButton(this, stop_text); 146 stop_button_ = new views::BlueButton(this, stop_text);
138 AddChildView(stop_button_); 147 AddChildView(stop_button_);
148
149 // TODO(jiayl): IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON is used for the need to
150 // merge to M34. Change it to a new IDS_ after the merge.
151 hide_link_ = new views::Link(
152 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON));
153 hide_link_->set_listener(this);
154 AddChildView(hide_link_);
139 } 155 }
140 156
141 ScreenCaptureNotificationUIViews::~ScreenCaptureNotificationUIViews() { 157 ScreenCaptureNotificationUIViews::~ScreenCaptureNotificationUIViews() {
142 stop_callback_.Reset(); 158 stop_callback_.Reset();
143 delete GetWidget(); 159 delete GetWidget();
144 } 160 }
145 161
146 void ScreenCaptureNotificationUIViews::OnStarted( 162 void ScreenCaptureNotificationUIViews::OnStarted(
147 const base::Closure& stop_callback) { 163 const base::Closure& stop_callback) {
148 stop_callback_ = stop_callback; 164 stop_callback_ = stop_callback;
149 165
150 label_->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE); 166 label_->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE);
151 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 167 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
152 label_->SetText(text_); 168 label_->SetText(text_);
153 169
154 views::Widget* widget = new views::Widget; 170 views::Widget* widget = new views::Widget;
155 171
156 views::Widget::InitParams params; 172 views::Widget::InitParams params;
157 params.delegate = this; 173 params.delegate = this;
158 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 174 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
159 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 175 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
160 params.remove_standard_frame = true; 176 params.remove_standard_frame = true;
161 params.keep_on_top = true; 177 params.keep_on_top = true;
162 params.top_level = true; 178 params.top_level = true;
163 params.can_activate = false; 179 // Make sure can_activate is true so the window icon will show in the taskbar.
180 params.can_activate = true;
164 181
165 #if defined(USE_ASH) 182 #if defined(USE_ASH)
166 // TODO(sergeyu): The notification bar must be shown on the monitor that's 183 // 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 184 // being captured. Make sure it's always the case. Currently we always capture
168 // the primary monitor. 185 // the primary monitor.
169 if (ash::Shell::HasInstance()) 186 if (ash::Shell::HasInstance())
170 params.context = ash::Shell::GetPrimaryRootWindow(); 187 params.context = ash::Shell::GetPrimaryRootWindow();
171 #endif 188 #endif
172 189
173 widget->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 190 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, 202 work_area.x() + work_area.width() / 2 - size.width() / 2,
186 work_area.y() + work_area.height() - size.height(), 203 work_area.y() + work_area.height() - size.height(),
187 size.width(), size.height()); 204 size.width(), size.height());
188 widget->SetBounds(bounds); 205 widget->SetBounds(bounds);
189 206
190 widget->Show(); 207 widget->Show();
191 } 208 }
192 209
193 gfx::Size ScreenCaptureNotificationUIViews::GetPreferredSize() { 210 gfx::Size ScreenCaptureNotificationUIViews::GetPreferredSize() {
194 gfx::Size grip_size = gripper_->GetPreferredSize(); 211 gfx::Size grip_size = gripper_->GetPreferredSize();
195 gfx::Size label_size = child_at(1)->GetPreferredSize(); 212 gfx::Size label_size = label_->GetPreferredSize();
196 gfx::Size button_size = child_at(2)->GetPreferredSize(); 213 gfx::Size stop_button_size = stop_button_->GetPreferredSize();
197 int width = kHorizontalMargin * 2 + grip_size.width() + label_size.width() + 214 gfx::Size hide_link_size = hide_link_->GetPreferredSize();
198 button_size.width(); 215 int width = kHorizontalMargin * 3 + grip_size.width() + label_size.width() +
216 stop_button_size.width() + hide_link_size.width();
199 width = std::max(width, kMinimumWidth); 217 width = std::max(width, kMinimumWidth);
200 width = std::min(width, kMaximumWidth); 218 width = std::min(width, kMaximumWidth);
201 return gfx::Size(width, std::max(label_size.height(), button_size.height())); 219 return gfx::Size(width, std::max(label_size.height(),
220 std::max(hide_link_size.height(),
221 stop_button_size.height())));
202 } 222 }
203 223
204 void ScreenCaptureNotificationUIViews::Layout() { 224 void ScreenCaptureNotificationUIViews::Layout() {
205 gfx::Rect grip_rect(gripper_->GetPreferredSize()); 225 gfx::Rect grip_rect(gripper_->GetPreferredSize());
206 grip_rect.set_y(bounds().height() / 2 - grip_rect.height() / 2); 226 grip_rect.set_y((bounds().height() - grip_rect.height()) / 2);
207 gripper_->SetBoundsRect(grip_rect); 227 gripper_->SetBoundsRect(grip_rect);
208 228
209 gfx::Rect button_rect(stop_button_->GetPreferredSize()); 229 gfx::Rect stop_button_rect(stop_button_->GetPreferredSize());
210 button_rect.set_x(bounds().width() - button_rect.width()); 230 gfx::Rect hide_link_rect(hide_link_->GetPreferredSize());
211 stop_button_->SetBoundsRect(button_rect); 231
232 hide_link_rect.set_x(bounds().width() - hide_link_rect.width());
233 hide_link_rect.set_y((bounds().height() - hide_link_rect.height()) / 2);
234 hide_link_->SetBoundsRect(hide_link_rect);
235
236 stop_button_rect.set_x(
237 hide_link_rect.x() - kHorizontalMargin - stop_button_rect.width());
238 stop_button_->SetBoundsRect(stop_button_rect);
212 239
213 gfx::Rect label_rect; 240 gfx::Rect label_rect;
214 label_rect.set_x(grip_rect.right() + kHorizontalMargin); 241 label_rect.set_x(grip_rect.right() + kHorizontalMargin);
215 label_rect.set_width(button_rect.x() - kHorizontalMargin - label_rect.x()); 242 label_rect.set_width(
243 stop_button_rect.x() - kHorizontalMargin - label_rect.x());
216 label_rect.set_height(bounds().height()); 244 label_rect.set_height(bounds().height());
217 label_->SetBoundsRect(label_rect); 245 label_->SetBoundsRect(label_rect);
218 246
219 client_view_->SetClientRect(button_rect); 247 client_view_->SetClientRect(gfx::Rect(
248 stop_button_rect.x(), stop_button_rect.y(),
249 stop_button_rect.width() + kHorizontalMargin + hide_link_rect.width(),
250 std::max(stop_button_rect.height(), hide_link_rect.height())));
220 } 251 }
221 252
222 void ScreenCaptureNotificationUIViews::DeleteDelegate() { 253 void ScreenCaptureNotificationUIViews::DeleteDelegate() {
223 NotifyStopped(); 254 NotifyStopped();
224 } 255 }
225 256
226 views::View* ScreenCaptureNotificationUIViews::GetContentsView() { 257 views::View* ScreenCaptureNotificationUIViews::GetContentsView() {
227 return this; 258 return this;
228 } 259 }
229 260
(...skipping 23 matching lines...) Expand all
253 } 284 }
254 285
255 bool ScreenCaptureNotificationUIViews::ShouldShowWindowTitle() const { 286 bool ScreenCaptureNotificationUIViews::ShouldShowWindowTitle() const {
256 return false; 287 return false;
257 } 288 }
258 289
259 bool ScreenCaptureNotificationUIViews::ShouldShowCloseButton() const { 290 bool ScreenCaptureNotificationUIViews::ShouldShowCloseButton() const {
260 return false; 291 return false;
261 } 292 }
262 293
294 bool ScreenCaptureNotificationUIViews::CanActivate() const {
295 // If we do not override this method, the window sometimes does not properly
296 // restore to its normal size on Windows.
297 return false;
298 }
299
263 void ScreenCaptureNotificationUIViews::ButtonPressed(views::Button* sender, 300 void ScreenCaptureNotificationUIViews::ButtonPressed(views::Button* sender,
264 const ui::Event& event) { 301 const ui::Event& event) {
265 NotifyStopped(); 302 NotifyStopped();
266 } 303 }
267 304
305 void ScreenCaptureNotificationUIViews::LinkClicked(views::Link* source,
306 int event_flags) {
307 GetWidget()->Minimize();
308 }
309
268 void ScreenCaptureNotificationUIViews::NotifyStopped() { 310 void ScreenCaptureNotificationUIViews::NotifyStopped() {
269 if (!stop_callback_.is_null()) { 311 if (!stop_callback_.is_null()) {
270 base::Closure callback = stop_callback_; 312 base::Closure callback = stop_callback_;
271 stop_callback_.Reset(); 313 stop_callback_.Reset();
272 callback.Run(); 314 callback.Run();
273 } 315 }
274 } 316 }
275 317
276 } // namespace 318 } // namespace
277 319
278 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create( 320 scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create(
279 const base::string16& text) { 321 const base::string16& text) {
280 return scoped_ptr<ScreenCaptureNotificationUI>( 322 return scoped_ptr<ScreenCaptureNotificationUI>(
281 new ScreenCaptureNotificationUIViews(text)); 323 new ScreenCaptureNotificationUIViews(text));
282 } 324 }
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