1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_
6#define ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_
7
8#include <map>
9
10#include "ash/ash_export.h"
11#include "ash/display/display_controller.h"
12#include "ash/display/display_info.h"
13#include "ash/system/tray/system_tray_item.h"
14#include "base/strings/string16.h"
15#include "ui/views/view.h"
16
17namespace ash {
18class DisplayView;
19
20namespace test {
21class AshTestBase;
22}
23
24class ASH_EXPORT TrayDisplay : public SystemTrayItem,
25                               public DisplayController::Observer {
26 public:
27  explicit TrayDisplay(SystemTray* system_tray);
28  virtual ~TrayDisplay();
29
30  // Overridden from DisplayControllerObserver:
31  virtual void OnDisplayConfigurationChanged() OVERRIDE;
32
33 private:
34  friend class TrayDisplayTest;
35
36  typedef std::map<int64, DisplayInfo> DisplayInfoMap;
37
38  static const char kNotificationId[];
39
40  // Scans the current display info and updates |display_info_|. Sets the
41  // previous data to |old_info| if it's not NULL.
42  void UpdateDisplayInfo(DisplayInfoMap* old_info);
43
44  // Compares the current display settings with |old_info| and determine what
45  // message should be shown for notification. Returns true if there's a
46  // meaningful change. Note that it's possible to return true and set
47  // |message_out| to empty, which means the notification should be removed. It
48  // also sets |additional_message_out| which appears in the notification with
49  // the |message_out|.
50  bool GetDisplayMessageForNotification(
51      const DisplayInfoMap& old_info,
52      base::string16* message_out,
53      base::string16* additional_message_out);
54
55  // Creates or updates the display notification.
56  void CreateOrUpdateNotification(const base::string16& message,
57                                  const base::string16& additional_message);
58
59  // Overridden from SystemTrayItem.
60  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
61  virtual void DestroyDefaultView() OVERRIDE;
62
63  // Test accessors.
64  base::string16 GetDefaultViewMessage() const;
65  bool GetAccessibleStateForTesting(ui::AXViewState* state);
66  const views::View* default_view() const {
67    return reinterpret_cast<views::View*>(default_);
68  }
69
70  DisplayView* default_;
71  DisplayInfoMap display_info_;
72
73  DISALLOW_COPY_AND_ASSIGN(TrayDisplay);
74};
75
76}  // namespace ash
77
78#endif  // ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_
79