clock_menu_button.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ 6#define CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ 7#pragma once 8 9#include "base/scoped_ptr.h" 10#include "base/timer.h" 11#include "chrome/browser/chromeos/cros/power_library.h" 12#include "chrome/browser/chromeos/cros/system_library.h" 13#include "chrome/browser/chromeos/status/status_area_button.h" 14#include "unicode/calendar.h" 15#include "views/controls/button/menu_button.h" 16#include "views/controls/menu/menu_2.h" 17#include "views/controls/menu/view_menu_delegate.h" 18 19namespace chromeos { 20 21class StatusAreaHost; 22 23// The clock menu button in the status area. 24// This button shows the current time. 25class ClockMenuButton : public StatusAreaButton, 26 public views::ViewMenuDelegate, 27 public ui::MenuModel, 28 public PowerLibrary::Observer, 29 public SystemLibrary::Observer { 30 public: 31 explicit ClockMenuButton(StatusAreaHost* host); 32 virtual ~ClockMenuButton(); 33 34 // ui::MenuModel implementation. 35 virtual bool HasIcons() const { return false; } 36 virtual int GetItemCount() const; 37 virtual ui::MenuModel::ItemType GetTypeAt(int index) const; 38 virtual int GetCommandIdAt(int index) const { return index; } 39 virtual string16 GetLabelAt(int index) const; 40 virtual bool IsItemDynamicAt(int index) const { return true; } 41 virtual bool GetAcceleratorAt(int index, 42 ui::Accelerator* accelerator) const { return false; } 43 virtual bool IsItemCheckedAt(int index) const { return false; } 44 virtual int GetGroupIdAt(int index) const { return 0; } 45 virtual bool GetIconAt(int index, SkBitmap* icon) const { return false; } 46 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const { 47 return NULL; 48 } 49 virtual bool IsEnabledAt(int index) const; 50 virtual ui::MenuModel* GetSubmenuModelAt(int index) const { return NULL; } 51 virtual void HighlightChangedTo(int index) {} 52 virtual void ActivatedAt(int index); 53 virtual void MenuWillShow() {} 54 55 // Overridden from ResumeLibrary::Observer: 56 virtual void PowerChanged(PowerLibrary* obj) {} 57 virtual void SystemResumed(); 58 59 // Overridden from SystemLibrary::Observer: 60 virtual void TimezoneChanged(const icu::TimeZone& timezone); 61 62 // Updates the time on the menu button. Can be called by host if timezone 63 // changes. 64 void UpdateText(); 65 66 protected: 67 virtual int horizontal_padding() { return 3; } 68 69 private: 70 // views::ViewMenuDelegate implementation. 71 virtual void RunMenu(views::View* source, const gfx::Point& pt); 72 73 // Updates text and schedules the timer to fire at the next minute interval. 74 void UpdateTextAndSetNextTimer(); 75 76 base::OneShotTimer<ClockMenuButton> timer_; 77 78 // The clock menu. 79 // NOTE: we use a scoped_ptr here as menu calls into 'this' from the 80 // constructor. 81 scoped_ptr<views::Menu2> clock_menu_; 82 83 StatusAreaHost* host_; 84 85 DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); 86}; 87 88} // namespace chromeos 89 90#endif // CHROME_BROWSER_CHROMEOS_STATUS_CLOCK_MENU_BUTTON_H_ 91