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

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

Issue 8557005: Rebase the MessageBubble on the new views bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on updated bubble move codereview.chromium.org/8650001. Created 9 years, 1 month 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
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/status/network_menu_button.h" 5 #include "chrome/browser/chromeos/status/network_menu_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 NetworkMenuButton::~NetworkMenuButton() { 127 NetworkMenuButton::~NetworkMenuButton() {
128 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); 128 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
129 netlib->RemoveNetworkManagerObserver(this); 129 netlib->RemoveNetworkManagerObserver(this);
130 netlib->RemoveObserverForAllNetworks(this); 130 netlib->RemoveObserverForAllNetworks(this);
131 netlib->RemoveCellularDataPlanObserver(this); 131 netlib->RemoveCellularDataPlanObserver(this);
132 if (!cellular_device_path_.empty()) 132 if (!cellular_device_path_.empty())
133 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); 133 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this);
134 if (mobile_data_bubble_) 134 if (mobile_data_bubble_)
135 mobile_data_bubble_->Close(); 135 mobile_data_bubble_->GetWidget()->Close();
136 } 136 }
137 137
138 // static 138 // static
139 void NetworkMenuButton::RegisterPrefs(PrefService* local_state) { 139 void NetworkMenuButton::RegisterPrefs(PrefService* local_state) {
140 // Carrier deal notification shown count defaults to 0. 140 // Carrier deal notification shown count defaults to 0.
141 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0); 141 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0);
142 } 142 }
143 143
144 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
145 // NetworkLibrary::NetworkDeviceObserver implementation: 145 // NetworkLibrary::NetworkDeviceObserver implementation:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 //////////////////////////////////////////////////////////////////////////////// 235 ////////////////////////////////////////////////////////////////////////////////
236 // NetworkMenuButton, NetworkMenuIcon::Delegate implementation: 236 // NetworkMenuButton, NetworkMenuIcon::Delegate implementation:
237 void NetworkMenuButton::NetworkMenuIconChanged() { 237 void NetworkMenuButton::NetworkMenuIconChanged() {
238 const SkBitmap bitmap = network_icon_->GetIconAndText(NULL); 238 const SkBitmap bitmap = network_icon_->GetIconAndText(NULL);
239 SetIcon(bitmap); 239 SetIcon(bitmap);
240 SchedulePaint(); 240 SchedulePaint();
241 } 241 }
242 242
243 //////////////////////////////////////////////////////////////////////////////// 243 ////////////////////////////////////////////////////////////////////////////////
244 // MessageBubbleDelegate implementation: 244 // views::Widget::Observer implementation:
245 245
246 void NetworkMenuButton::BubbleClosing(Bubble* bubble, bool closed_by_escape) { 246 void NetworkMenuButton::OnWidgetClosing(views::Widget* widget) {
247 if (!mobile_data_bubble_ || mobile_data_bubble_->GetWidget() != widget)
Nikita (slow) 2011/11/23 13:30:12 I've checked this patch on Chrome OS. OnWidgetClos
msw 2011/11/29 00:11:07 Fixed (added the observer on bubble construction).
248 return;
249
247 mobile_data_bubble_ = NULL; 250 mobile_data_bubble_ = NULL;
248 deal_info_url_.clear(); 251 deal_info_url_.clear();
249 deal_topup_url_.clear(); 252 deal_topup_url_.clear();
250 } 253 }
251 254
252 bool NetworkMenuButton::CloseOnEscape() { 255 ////////////////////////////////////////////////////////////////////////////////
253 return true; 256 // MessageBubbleLinkListener implementation:
254 }
255
256 bool NetworkMenuButton::FadeInOnShow() {
257 return false;
258 }
259 257
260 void NetworkMenuButton::OnLinkActivated(size_t index) { 258 void NetworkMenuButton::OnLinkActivated(size_t index) {
261 // If we have deal info URL defined that means that there're 259 // If we have deal info URL defined that means that there're
262 // 2 links in bubble. Let the user close it manually then thus giving ability 260 // 2 links in bubble. Let the user close it manually then thus giving ability
263 // to navigate to second link. 261 // to navigate to second link.
264 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback. 262 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback.
265 if (deal_info_url_.empty() && mobile_data_bubble_) 263 if (deal_info_url_.empty() && mobile_data_bubble_)
266 mobile_data_bubble_->Close(); 264 mobile_data_bubble_->GetWidget()->Close();
267 265
268 std::string deal_url_to_open; 266 std::string deal_url_to_open;
269 if (index == 0) { 267 if (index == 0) {
270 if (!deal_topup_url_.empty()) { 268 if (!deal_topup_url_.empty()) {
271 deal_url_to_open = deal_topup_url_; 269 deal_url_to_open = deal_topup_url_;
272 } else { 270 } else {
273 const Network* cellular = 271 const Network* cellular =
274 CrosLibrary::Get()->GetNetworkLibrary()->cellular_network(); 272 CrosLibrary::Get()->GetNetworkLibrary()->cellular_network();
275 if (!cellular) 273 if (!cellular)
276 return; 274 return;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 base::Bind( 403 base::Bind(
406 &NetworkMenuButton::ShowOptionalMobileDataPromoNotification, 404 &NetworkMenuButton::ShowOptionalMobileDataPromoNotification,
407 weak_ptr_factory_.GetWeakPtr(), 405 weak_ptr_factory_.GetWeakPtr(),
408 cros), 406 cros),
409 kPromoShowDelayMs); 407 kPromoShowDelayMs);
410 } 408 }
411 return; 409 return;
412 } 410 }
413 411
414 // Add deal text if it's defined. 412 // Add deal text if it's defined.
415 std::wstring notification_text; 413 string16 notification_text;
416 std::wstring default_text = 414 string16 default_text =
417 UTF16ToWide(l10n_util::GetStringUTF16(IDS_3G_NOTIFICATION_MESSAGE)); 415 l10n_util::GetStringUTF16(IDS_3G_NOTIFICATION_MESSAGE);
418 if (!deal_text.empty()) { 416 if (!deal_text.empty()) {
419 notification_text = StringPrintf(L"%ls\n\n%ls", 417 notification_text =
420 UTF8ToWide(deal_text).c_str(), 418 UTF8ToUTF16(deal_text) + UTF8ToUTF16("\n\n") + default_text;
421 default_text.c_str());
422 } else { 419 } else {
423 notification_text = default_text; 420 notification_text = default_text;
424 } 421 }
425 422
426 // Use deal URL if it's defined or general "Network Settings" URL. 423 // Use deal URL if it's defined or general "Network Settings" URL.
427 int link_message_id; 424 int link_message_id;
428 if (deal_topup_url_.empty()) 425 if (deal_topup_url_.empty())
429 link_message_id = IDS_OFFLINE_NETWORK_SETTINGS; 426 link_message_id = IDS_OFFLINE_NETWORK_SETTINGS;
430 else 427 else
431 link_message_id = IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT; 428 link_message_id = IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT;
432 429
433 std::vector<std::wstring> links; 430 std::vector<string16> links;
434 links.push_back(UTF16ToWide(l10n_util::GetStringUTF16(link_message_id))); 431 links.push_back(l10n_util::GetStringUTF16(link_message_id));
435 if (!deal_info_url_.empty()) 432 if (!deal_info_url_.empty())
436 links.push_back(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); 433 links.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
437 mobile_data_bubble_ = MessageBubble::ShowWithLinks( 434 mobile_data_bubble_ = new MessageBubble(
438 GetWidget(), 435 this,
439 button_bounds, 436 views::BubbleBorder::TOP_RIGHT,
440 views::BubbleBorder::TOP_RIGHT ,
441 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_NOTIFICATION_3G), 437 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_NOTIFICATION_3G),
442 notification_text, 438 notification_text,
443 links, 439 links);
444 this); 440 mobile_data_bubble_->set_link_listener(this);
441 MessageBubble::ShowBubble(mobile_data_bubble_);
445 442
446 check_for_promo_ = false; 443 check_for_promo_ = false;
447 SetShow3gPromoNotification(false); 444 SetShow3gPromoNotification(false);
448 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) 445 if (carrier_deal_promo_pref != kNotificationCountPrefDefault)
449 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); 446 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1);
450 } 447 }
451 } 448 }
452 449
453 void NetworkMenuButton::SetTooltipAndAccessibleName(const string16& label) { 450 void NetworkMenuButton::SetTooltipAndAccessibleName(const string16& label) {
454 SetTooltipText(label); 451 SetTooltipText(label);
455 SetAccessibleName(label); 452 SetAccessibleName(label);
456 } 453 }
457 454
458 } // namespace chromeos 455 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698