| Index: chrome/browser/chromeos/status_area_view.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/status_area_view.cc (revision 26831)
|
| +++ chrome/browser/chromeos/status_area_view.cc (working copy)
|
| @@ -5,18 +5,21 @@
|
| #include "chrome/browser/chromeos/status_area_view.h"
|
|
|
| #include <algorithm>
|
| +#include <dlfcn.h>
|
|
|
| #include "app/gfx/canvas.h"
|
| #include "app/gfx/font.h"
|
| #include "app/l10n_util.h"
|
| #include "app/resource_bundle.h"
|
| #include "app/theme_provider.h"
|
| +#include "base/path_service.h"
|
| #include "base/string_util.h"
|
| #include "base/time.h"
|
| #include "base/timer.h"
|
| #include "chrome/app/chrome_dll_resource.h"
|
| #include "chrome/browser/browser.h"
|
| #include "chrome/browser/browser_window.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| #include "chrome/browser/gtk/browser_window_gtk.h"
|
| #include "chrome/browser/profile.h"
|
| #include "grit/chromium_strings.h"
|
| @@ -29,6 +32,9 @@
|
|
|
| namespace {
|
|
|
| +// The number of images representing the fullness of the battery.
|
| +const int kNumBatteryImages = 8;
|
| +
|
| // Number of pixels to separate adjacent status items.
|
| const int kStatusItemSeparation = 1;
|
|
|
| @@ -61,7 +67,7 @@
|
|
|
| ClockView::ClockView()
|
| : font_(ResourceBundle::GetSharedInstance().GetFont(
|
| - ResourceBundle::BaseFont)) {
|
| + ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD)) {
|
| SetNextTimer();
|
| }
|
|
|
| @@ -69,17 +75,21 @@
|
| }
|
|
|
| gfx::Size ClockView::GetPreferredSize() {
|
| - return gfx::Size(40, 10);
|
| + return gfx::Size(40, 12);
|
| }
|
|
|
| void ClockView::Paint(gfx::Canvas* canvas) {
|
| base::Time now = base::Time::Now();
|
| base::Time::Exploded now_exploded;
|
| now.LocalExplode(&now_exploded);
|
| + int hour = now_exploded.hour % 12;
|
| + if (hour == 0)
|
| + hour = 12;
|
|
|
| - std::wstring time_string = StringPrintf(L"%d:%02d",
|
| - now_exploded.hour,
|
| - now_exploded.minute);
|
| + std::wstring time_string = StringPrintf(L"%d:%02d%lc",
|
| + hour,
|
| + now_exploded.minute,
|
| + now_exploded.hour < 12 ? L'p' : L'p');
|
| canvas->DrawStringInt(time_string, font_, SK_ColorWHITE, 0, 0,
|
| width(), height(), gfx::Canvas::TEXT_ALIGN_CENTER);
|
| }
|
| @@ -185,31 +195,44 @@
|
| StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ =
|
| StatusAreaView::OPEN_TABS_ON_LEFT;
|
|
|
| +// static
|
| +void* StatusAreaView::power_library_ = NULL;
|
| +bool StatusAreaView::power_library_error_ = false;
|
| +
|
| StatusAreaView::StatusAreaView(Browser* browser)
|
| : browser_(browser),
|
| battery_view_(NULL),
|
| - menu_view_(NULL) {
|
| + menu_view_(NULL),
|
| + power_status_connection_(NULL) {
|
| }
|
|
|
| StatusAreaView::~StatusAreaView() {
|
| + if (power_status_connection_)
|
| + chromeos::DisconnectPowerStatus(power_status_connection_);
|
| }
|
|
|
| void StatusAreaView::Init() {
|
| - ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
|
| + LoadPowerLibrary();
|
| + ThemeProvider* theme = browser_->profile()->GetThemeProvider();
|
|
|
| + // Clock.
|
| + AddChildView(new ClockView);
|
| +
|
| // Battery.
|
| battery_view_ = new views::ImageView;
|
| - battery_view_->SetImage(
|
| - resource_bundle.GetBitmapNamed(IDR_STATUSBAR_BATTERY));
|
| + battery_view_->SetImage(theme->GetBitmapNamed(IDR_STATUSBAR_BATTERY_UNKNOWN));
|
| AddChildView(battery_view_);
|
|
|
| - // Clock.
|
| - AddChildView(new ClockView);
|
| -
|
| // Menu.
|
| menu_view_ = new views::MenuButton(NULL, std::wstring(), this, false);
|
| - menu_view_->SetIcon(*resource_bundle.GetBitmapNamed(IDR_STATUSBAR_MENU));
|
| + menu_view_->SetIcon(*theme->GetBitmapNamed(IDR_STATUSBAR_MENU));
|
| AddChildView(menu_view_);
|
| +
|
| + if (power_library_) {
|
| + power_status_connection_ = chromeos::MonitorPowerStatus(
|
| + StatusAreaView::PowerStatusChangedHandler,
|
| + this);
|
| + }
|
| }
|
|
|
| gfx::Size StatusAreaView::GetPreferredSize() {
|
| @@ -331,3 +354,57 @@
|
| CreateAppMenu();
|
| app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
|
| }
|
| +
|
| +// static
|
| +void StatusAreaView::LoadPowerLibrary() {
|
| + if (power_library_) {
|
| + // Already loaded.
|
| + return;
|
| + }
|
| +
|
| + if (power_library_error_) {
|
| + // Error in previous load attempt.
|
| + return;
|
| + }
|
| +
|
| + FilePath path;
|
| + if (PathService::Get(chrome::FILE_CHROMEOS_API, &path)) {
|
| + power_library_ = dlopen(path.value().c_str(), RTLD_NOW);
|
| + if (power_library_) {
|
| + chromeos::LoadPower(power_library_);
|
| + } else {
|
| + power_library_error_ = true;
|
| + char* error = dlerror();
|
| + if (error) {
|
| + LOG(ERROR) << "Problem loading chromeos shared object: " << error;
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| +// static
|
| +void StatusAreaView::PowerStatusChangedHandler(
|
| + void* object, const chromeos::PowerStatus& status) {
|
| + static_cast<StatusAreaView*>(object)->PowerStatusChanged(status);
|
| +}
|
| +
|
| +void StatusAreaView::PowerStatusChanged(const chromeos::PowerStatus& status) {
|
| + ThemeProvider* theme = browser_->profile()->GetThemeProvider();
|
| + int image_index;
|
| +
|
| + if (status.battery_state == chromeos::BATTERY_STATE_FULLY_CHARGED &&
|
| + status.line_power_on) {
|
| + image_index = IDR_STATUSBAR_BATTERY_CHARGED;
|
| + } else {
|
| + image_index = status.line_power_on ?
|
| + IDR_STATUSBAR_BATTERY_CHARGING_1 :
|
| + IDR_STATUSBAR_BATTERY_DISCHARGING_1;
|
| + double percentage = status.battery_percentage;
|
| + int offset = floor(percentage / (100.0 / kNumBatteryImages));
|
| + // This can happen if the battery is 100% full.
|
| + if (offset == kNumBatteryImages)
|
| + offset--;
|
| + image_index += offset;
|
| + }
|
| + battery_view_->SetImage(theme->GetBitmapNamed(image_index));
|
| +}
|
|
|