15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/chromeos/tray_display.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/display_controller.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
10424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ash/system/system_notifier.h"
11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/system/tray/actionable_view.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/fixed_sized_image_view.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_constants.h"
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/system/tray/tray_notification_view.h"
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/wm/maximize_mode/maximize_mode_controller.h"
18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/bind.h"
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/strings/string_util.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/ash_resources.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/ash_strings.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
25eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/message_center/message_center.h"
26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/message_center/notification.h"
27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/message_center/notification_delegate.h"
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/views/controls/image_view.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/label.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/box_layout.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing message_center::Notification;
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochDisplayManager* GetDisplayManager() {
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return Shell::GetInstance()->display_manager();
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbase::string16 GetDisplayName(int64 display_id) {
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return base::UTF8ToUTF16(
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetDisplayManager()->GetDisplayNameForId(display_id));
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochbase::string16 GetDisplaySize(int64 display_id) {
477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DisplayManager* display_manager = GetDisplayManager();
487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  const gfx::Display* display = &display_manager->GetDisplayForId(display_id);
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // We don't show display size for mirrored display. Fallback
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // to empty string if this happens on release build.
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool mirrored_display = display_manager->mirrored_display_id() == display_id;
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DCHECK(!mirrored_display);
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (mirrored_display)
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return base::string16();
577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DCHECK(display->is_valid());
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return base::UTF8ToUTF16(display->size().ToString());
607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Returns 1-line information for the specified display, like
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// "InternalDisplay: 1280x750"
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbase::string16 GetDisplayInfoLine(int64 display_id) {
65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const DisplayInfo& display_info =
66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      GetDisplayManager()->GetDisplayInfo(display_id);
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (GetDisplayManager()->mirrored_display_id() == display_id)
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return GetDisplayName(display_id);
69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  base::string16 size_text = GetDisplaySize(display_id);
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::string16 display_data;
72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (display_info.has_overscan()) {
73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    display_data = l10n_util::GetStringFUTF16(
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION,
75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        size_text,
76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        l10n_util::GetStringUTF16(
77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  } else {
79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    display_data = size_text;
80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return l10n_util::GetStringFUTF16(
83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      GetDisplayName(display_id),
85eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      display_data);
86eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
87eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbase::string16 GetAllDisplayInfo() {
89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  DisplayManager* display_manager = GetDisplayManager();
90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::vector<base::string16> lines;
91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  int64 internal_id = gfx::Display::kInvalidDisplayID;
92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Make sure to show the internal display first.
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (display_manager->HasInternalDisplay() &&
94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      display_manager->IsInternalDisplayId(
95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch          display_manager->first_display_id())) {
96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    internal_id = display_manager->first_display_id();
97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    lines.push_back(GetDisplayInfoLine(internal_id));
98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
101ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    int64 id = display_manager->GetDisplayAt(i).id();
102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (id == internal_id)
103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      continue;
104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    lines.push_back(GetDisplayInfoLine(id));
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return JoinString(lines, '\n');
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
110424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void OpenSettings() {
111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // switch is intentionally introduced without default, to cause an error when
112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // a new type of login status is introduced.
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  switch (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()) {
114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_NONE:
115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_LOCKED:
116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      return;
117a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_USER:
119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_OWNER:
120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_GUEST:
121a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_RETAIL_MODE:
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_PUBLIC:
1235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    case user::LOGGED_IN_SUPERVISED:
124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    case user::LOGGED_IN_KIOSK_APP:
1256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ash::SystemTrayDelegate* delegate =
1266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          Shell::GetInstance()->system_tray_delegate();
1276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      if (delegate->ShouldShowSettings())
1286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        delegate->ShowDisplaySettings();
129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace
133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char TrayDisplay::kNotificationId[] = "chrome://settings/display";
1353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
136c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass DisplayView : public ActionableView {
137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public:
138424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  explicit DisplayView() {
139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    SetLayoutManager(new views::BoxLayout(
140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        views::BoxLayout::kHorizontal,
1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        kTrayPopupPaddingHorizontal, 0,
1428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        kTrayPopupPaddingBetweenItems));
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
145c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    image_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    image_->SetImage(
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia());
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    AddChildView(image_);
149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    label_ = new views::Label();
151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    label_->SetMultiLine(true);
152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    AddChildView(label_);
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Update();
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~DisplayView() {}
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Update() {
1603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    base::string16 message = GetTrayDisplayMessage(NULL);
161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (message.empty() && ShouldShowFirstDisplayInfo())
162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      message = GetDisplayInfoLine(GetDisplayManager()->first_display_id());
163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    SetVisible(!message.empty());
164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    label_->SetText(message);
165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    SetAccessibleName(message);
166d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    Layout();
167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  const views::Label* label() const { return label_; }
170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Overridden from views::View.
172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool GetTooltipText(const gfx::Point& p,
173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                              base::string16* tooltip) const OVERRIDE {
1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    base::string16 tray_message = GetTrayDisplayMessage(NULL);
175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    base::string16 display_message = GetAllDisplayInfo();
176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (tray_message.empty() && display_message.empty())
177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      return false;
178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    *tooltip = tray_message + base::ASCIIToUTF16("\n") + display_message;
180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return true;
1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns the name of the currently connected external display.
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // This should not be used when the external display is used for
185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // mirroring.
186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static base::string16 GetExternalDisplayName() {
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DisplayManager* display_manager = GetDisplayManager();
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DCHECK(!display_manager->IsMirrored());
189f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
190f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    int64 external_id = gfx::Display::kInvalidDisplayID;
191f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
192f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      int64 id = display_manager->GetDisplayAt(i).id();
193f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      if (id != gfx::Display::InternalDisplayId()) {
194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        external_id = id;
195f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        break;
196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      }
197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
199f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (external_id == gfx::Display::kInvalidDisplayID) {
200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return l10n_util::GetStringUTF16(
201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
204f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // The external display name may have an annotation of "(width x height)" in
205f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // case that the display is rotated or its resolution is changed.
206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    base::string16 name = GetDisplayName(external_id);
207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const DisplayInfo& display_info =
208f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        display_manager->GetDisplayInfo(external_id);
209f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (display_info.rotation() != gfx::Display::ROTATE_0 ||
210f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        display_info.configured_ui_scale() != 1.0f ||
211f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        !display_info.overscan_insets_in_dip().empty()) {
212f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      name = l10n_util::GetStringFUTF16(
213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          name, GetDisplaySize(external_id));
215f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    } else if (display_info.overscan_insets_in_dip().empty() &&
216f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)               display_info.has_overscan()) {
217f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      name = l10n_util::GetStringFUTF16(
218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
219f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          name, l10n_util::GetStringUTF16(
220f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
221f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
222f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
223f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return name;
224f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
226f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static base::string16 GetTrayDisplayMessage(
227f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      base::string16* additional_message_out) {
228f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DisplayManager* display_manager = GetDisplayManager();
229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (display_manager->GetNumDisplays() > 1) {
230f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      if (GetDisplayManager()->HasInternalDisplay()) {
231f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        return l10n_util::GetStringFUTF16(
232f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName());
233f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      }
234f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return l10n_util::GetStringUTF16(
235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
236f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
237f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
238f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (display_manager->IsMirrored()) {
239f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      if (GetDisplayManager()->HasInternalDisplay()) {
240f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        return l10n_util::GetStringFUTF16(
241f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
242f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            GetDisplayName(display_manager->mirrored_display_id()));
243f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      }
244f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return l10n_util::GetStringUTF16(
245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL);
246f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
248f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id();
249f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (display_manager->HasInternalDisplay() &&
250f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        !display_manager->IsInternalDisplayId(primary_id)) {
251f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      if (additional_message_out) {
252f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        *additional_message_out = l10n_util::GetStringUTF16(
253f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION);
254f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      }
255f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED);
256f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
257f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
258f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return base::string16();
259f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
260f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool ShouldShowFirstDisplayInfo() const {
263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo(
264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        GetDisplayManager()->first_display_id());
265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return display_info.rotation() != gfx::Display::ROTATE_0 ||
266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        display_info.configured_ui_scale() != 1.0f ||
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        !display_info.overscan_insets_in_dip().empty() ||
268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        display_info.has_overscan();
269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from ActionableView.
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool PerformAction(const ui::Event& event) OVERRIDE {
273424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    OpenSettings();
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE {
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 -
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        kTrayPopupPaddingBetweenItems - image_->GetPreferredSize().width();
280eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    label_->SizeToFit(label_max_width);
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::ImageView* image_;
284eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  views::Label* label_;
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(DisplayView);
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrayDisplay::TrayDisplay(SystemTray* system_tray)
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : SystemTrayItem(system_tray),
291eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      default_(NULL) {
292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Shell::GetInstance()->display_controller()->AddObserver(this);
293c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  UpdateDisplayInfo(NULL);
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrayDisplay::~TrayDisplay() {
297868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Shell::GetInstance()->display_controller()->RemoveObserver(this);
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
300c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochvoid TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) {
301c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  if (old_info)
302c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch    old_info->swap(display_info_);
303c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  display_info_.clear();
304c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
305eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  DisplayManager* display_manager = GetDisplayManager();
306eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
307ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    int64 id = display_manager->GetDisplayAt(i).id();
308eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    display_info_[id] = display_manager->GetDisplayInfo(id);
309eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
310c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch}
311eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
312c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdochbool TrayDisplay::GetDisplayMessageForNotification(
3133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    const TrayDisplay::DisplayInfoMap& old_info,
3143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    base::string16* message_out,
3153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    base::string16* additional_message_out) {
316eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Display is added or removed. Use the same message as the one in
317eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the system tray.
318ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (display_info_.size() != old_info.size()) {
319f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out);
320ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return true;
321ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
322eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
323eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  for (DisplayInfoMap::const_iterator iter = display_info_.begin();
324eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch       iter != display_info_.end(); ++iter) {
325eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first);
326ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // The display's number is same but different displays. This happens
327ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // for the transition between docked mode and mirrored display. Falls back
328ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // to GetTrayDisplayMessage().
329ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    if (old_iter == old_info.end()) {
330f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out);
331ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      return true;
332ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    }
333eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
334f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (iter->second.configured_ui_scale() !=
335f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        old_iter->second.configured_ui_scale()) {
3363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      *message_out = l10n_util::GetStringFUTF16(
337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch          IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
338eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch          GetDisplayName(iter->first),
3397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          GetDisplaySize(iter->first));
340ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      return true;
341eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    }
342eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (iter->second.rotation() != old_iter->second.rotation()) {
343ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      int rotation_text_id = 0;
344ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      switch (iter->second.rotation()) {
345ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        case gfx::Display::ROTATE_0:
346ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_STANDARD_ORIENTATION;
347ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          break;
348ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        case gfx::Display::ROTATE_90:
349ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90;
350ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          break;
351ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        case gfx::Display::ROTATE_180:
352ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_180;
353ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          break;
354ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        case gfx::Display::ROTATE_270:
355ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          rotation_text_id = IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_270;
356ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          break;
357ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      }
3583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      *message_out = l10n_util::GetStringFUTF16(
359ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED,
360ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          GetDisplayName(iter->first),
361ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch          l10n_util::GetStringUTF16(rotation_text_id));
362ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      return true;
363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    }
364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Found nothing special
367ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  return false;
368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void TrayDisplay::CreateOrUpdateNotification(
3713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    const base::string16& message,
3723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    const base::string16& additional_message) {
3733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Always remove the notification to make sure the notification appears
3743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // as a popup in any situation.
3753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  message_center::MessageCenter::Get()->RemoveNotification(
3763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      kNotificationId, false /* by_user */);
3773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
3783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (message.empty())
3793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return;
3803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
381cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Don't display notifications for accelerometer triggered screen rotations.
382cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // See http://crbug.com/364949
383cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (Shell::GetInstance()->maximize_mode_controller()->
38403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      ignore_display_configuration_updates()) {
385cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return;
386cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
387cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
3883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
3893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<Notification> notification(new Notification(
3903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      message_center::NOTIFICATION_TYPE_SIMPLE,
3913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      kNotificationId,
3923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      message,
3933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      additional_message,
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
3953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      base::string16(),  // display_source
396a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      message_center::NotifierId(
397a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          message_center::NotifierId::SYSTEM_COMPONENT,
398a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          system_notifier::kNotifierDisplay),
3993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      message_center::RichNotificationData(),
4003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      new message_center::HandleNotificationClickedDelegate(
401424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)          base::Bind(&OpenSettings))));
402cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
403cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    message_center::MessageCenter::Get()->AddNotification(notification.Pass());
4043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
4053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) {
407868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DCHECK(default_ == NULL);
408424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  default_ = new DisplayView();
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return default_;
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
412868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void TrayDisplay::DestroyDefaultView() {
413868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  default_ = NULL;
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TrayDisplay::OnDisplayConfigurationChanged() {
417c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  DisplayInfoMap old_info;
418c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  UpdateDisplayInfo(&old_info);
419c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
420d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (default_)
421d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    default_->Update();
422d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
423eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!Shell::GetInstance()->system_tray_delegate()->
424eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch          ShouldShowDisplayNotification()) {
425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
427eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
428ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  base::string16 message;
4293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  base::string16 additional_message;
4303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (GetDisplayMessageForNotification(old_info, &message, &additional_message))
4313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    CreateOrUpdateNotification(message, additional_message);
432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)base::string16 TrayDisplay::GetDefaultViewMessage() const {
435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!default_ || !default_->visible())
436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return base::string16();
437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return static_cast<DisplayView*>(default_)->label()->text();
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
441a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) {
442a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  views::View* view = default_;
443a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (view) {
444a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    view->GetAccessibleState(state);
445a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return true;
446a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
447a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return false;
448a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
449a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
451