diff options
author | benrg@chromium.org <benrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-02 22:35:47 +0000 |
---|---|---|
committer | benrg@chromium.org <benrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-02 22:35:47 +0000 |
commit | b2e8e0bde68e71b365d556c029299c80439cbef7 (patch) | |
tree | da9fe42556d4d39cc6a34bbd1150414d54c7cc4e | |
parent | 37f6bd5cb505ea5f1bf3ccd99e374a938298da96 (diff) | |
download | chromium_src-b2e8e0bde68e71b365d556c029299c80439cbef7.zip chromium_src-b2e8e0bde68e71b365d556c029299c80439cbef7.tar.gz chromium_src-b2e8e0bde68e71b365d556c029299c80439cbef7.tar.bz2 |
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
-rw-r--r-- | ash/ash_strings.grd | 3 | ||||
-rw-r--r-- | 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. <message name="IDS_ASH_STATUS_TRAY_WIFI" desc="The wifi network device."> Wi-Fi </message> + <message name="IDS_ASH_STATUS_TRAY_NO_NETWORKS" desc="The message to display in the network info bubble when it is otherwise empty."> + No network information available + </message> <message name="IDS_ASH_SECONDARY_MONITOR" desc="The message shown on the secondary monitors."> This screen intentionally left blank </message> 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; } |