tray_display.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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 {
18namespace test {
19class AshTestBase;
20}
21
22namespace internal {
23class DisplayView;
24
25class ASH_EXPORT TrayDisplay : public SystemTrayItem,
26                               public DisplayController::Observer {
27 public:
28  explicit TrayDisplay(SystemTray* system_tray);
29  virtual ~TrayDisplay();
30
31  // Overridden from DisplayControllerObserver:
32  virtual void OnDisplayConfigurationChanged() OVERRIDE;
33
34 private:
35  friend class TrayDisplayTest;
36
37  typedef std::map<int64, DisplayInfo> DisplayInfoMap;
38
39  static const char kNotificationId[];
40
41  // Scans the current display info and updates |display_info_|. Sets the
42  // previous data to |old_info| if it's not NULL.
43  void UpdateDisplayInfo(DisplayInfoMap* old_info);
44
45  // Compares the current display settings with |old_info| and determine what
46  // message should be shown for notification. Returns true if there's a
47  // meaningful change. Note that it's possible to return true and set
48  // |message_out| to empty, which means the notification should be removed. It
49  // also sets |additional_message_out| which appears in the notification with
50  // the |message_out|.
51  bool GetDisplayMessageForNotification(
52      const DisplayInfoMap& old_info,
53      base::string16* message_out,
54      base::string16* additional_message_out);
55
56  // Creates or updates the display notification.
57  void CreateOrUpdateNotification(const base::string16& message,
58                                  const base::string16& additional_message);
59
60  // Overridden from SystemTrayItem.
61  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
62  virtual void DestroyDefaultView() OVERRIDE;
63
64  // Test accessors.
65  base::string16 GetDefaultViewMessage() const;
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 internal
77}  // namespace ash
78
79#endif  // ASH_SYSTEM_CHROMEOS_TRAY_DISPLAY_H_
80