From b2e8e0bde68e71b365d556c029299c80439cbef7 Mon Sep 17 00:00:00 2001 From: "benrg@chromium.org" Date: Wed, 2 May 2012 22:35:47 +0000 Subject: In the network info bubble, don't display IP or MAC addresses that don't exist BUG=120533 TEST=manual Review URL: http://codereview.chromium.org/10284002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135009 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/ash_strings.grd | 3 ++ ash/system/network/tray_network.cc | 63 ++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd index 92538d7..09de499 100644 --- a/ash/ash_strings.grd +++ b/ash/ash_strings.grd @@ -344,6 +344,9 @@ Press Search key to cancel. Wi-Fi + + No network information available + This screen intentionally left blank diff --git a/ash/system/network/tray_network.cc b/ash/system/network/tray_network.cc index 36334c6..e585b2c 100644 --- a/ash/system/network/tray_network.cc +++ b/ash/system/network/tray_network.cc @@ -39,29 +39,24 @@ namespace { // Height of the list of networks in the popup. const int kNetworkListHeight = 203; -// Creates a row of labels. -views::View* CreateTextLabels(const string16& text_label, - const std::string& text_string) { +// Create a label with the font size and color used in the network info bubble. +views::Label* CreateInfoBubbleLabel(const string16& text) { const SkColor text_color = SkColorSetARGB(127, 0, 0, 0); - views::View* view = new views::View; - view->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, - 0, 0, 1)); - - views::Label* label = new views::Label(text_label); - label->SetFont(label->font().DeriveFont(-1)); - label->SetEnabledColor(text_color); - view->AddChildView(label); - - label = new views::Label(UTF8ToUTF16(": ")); - label->SetFont(label->font().DeriveFont(-1)); - label->SetEnabledColor(text_color); - view->AddChildView(label); - - label = new views::Label(UTF8ToUTF16(text_string)); + views::Label* label = new views::Label(text); label->SetFont(label->font().DeriveFont(-1)); label->SetEnabledColor(text_color); - view->AddChildView(label); + return label; +} +// Create a row of labels for the network info bubble. +views::View* CreateInfoBubbleLine(const string16& text_label, + const std::string& text_string) { + views::View* view = new views::View; + view->SetLayoutManager( + new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1)); + view->AddChildView(CreateInfoBubbleLabel(text_label)); + view->AddChildView(CreateInfoBubbleLabel(UTF8ToUTF16(": "))); + view->AddChildView(CreateInfoBubbleLabel(UTF8ToUTF16(text_string))); return view; } @@ -381,14 +376,28 @@ class NetworkDetailedView : public views::View, views::View* container = new views::View; container->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); - container->set_border(views::Border::CreateEmptyBorder(0, 20, 0, 0)); - - container->AddChildView(CreateTextLabels(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_IP), ip_address)); - container->AddChildView(CreateTextLabels(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_ETHERNET), ethernet_address)); - container->AddChildView(CreateTextLabels(bundle.GetLocalizedString( - IDS_ASH_STATUS_TRAY_WIFI), wifi_address)); + container->set_border(views::Border::CreateEmptyBorder(0, 5, 0, 5)); + + // GetNetworkAddresses returns empty strings if no information is available. + if (!ip_address.empty()) { + container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( + IDS_ASH_STATUS_TRAY_IP), ip_address)); + } + if (!ethernet_address.empty()) { + container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( + IDS_ASH_STATUS_TRAY_ETHERNET), ethernet_address)); + } + if (!wifi_address.empty()) { + container->AddChildView(CreateInfoBubbleLine(bundle.GetLocalizedString( + IDS_ASH_STATUS_TRAY_WIFI), wifi_address)); + } + + // Avoid an empty bubble in the unlikely event that there is no network + // information at all. + if (!container->has_children()) { + container->AddChildView(CreateInfoBubbleLabel(bundle.GetLocalizedString( + IDS_ASH_STATUS_TRAY_NO_NETWORKS))); + } return container; } -- cgit v1.1