| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/status/status_area_view.h" | 5 #include "chrome/browser/chromeos/status/status_area_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "chrome/browser/chromeos/status/accessibility_menu_button.h" | 11 #include "chrome/browser/chromeos/status/accessibility_menu_button.h" |
| 12 #include "chrome/browser/chromeos/status/caps_lock_menu_button.h" | 12 #include "chrome/browser/chromeos/status/caps_lock_menu_button.h" |
| 13 #include "chrome/browser/chromeos/status/clock_menu_button.h" | 13 #include "chrome/browser/chromeos/status/clock_menu_button.h" |
| 14 #include "chrome/browser/chromeos/status/input_method_menu_button.h" | 14 #include "chrome/browser/chromeos/status/input_method_menu_button.h" |
| 15 #include "chrome/browser/chromeos/status/memory_menu_button.h" | 15 #include "chrome/browser/chromeos/status/memory_menu_button.h" |
| 16 #include "chrome/browser/chromeos/status/network_menu_button.h" | 16 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 17 #include "chrome/browser/chromeos/status/power_menu_button.h" | 17 #include "chrome/browser/chromeos/status/power_menu_button.h" |
| 18 #include "chrome/browser/chromeos/status/status_area_host.h" | |
| 19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 20 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 23 #include "views/border.h" | 22 #include "views/border.h" |
| 24 #include "views/controls/image_view.h" | 23 #include "views/controls/image_view.h" |
| 25 | 24 |
| 26 namespace chromeos { | |
| 27 | |
| 28 // Number of pixels to separate each icon. | 25 // Number of pixels to separate each icon. |
| 29 #if defined(TOUCH_UI) | 26 #if defined(TOUCH_UI) |
| 30 const int kSeparation = 25; | 27 const int kSeparation = 25; |
| 31 #else | 28 #else |
| 32 const int kSeparation = 0; | 29 const int kSeparation = 0; |
| 33 #endif | 30 #endif |
| 34 | 31 |
| 35 StatusAreaView::StatusAreaView(StatusAreaHost* host) | 32 StatusAreaView::StatusAreaView() |
| 36 : host_(host), | 33 : need_return_focus_(false) { |
| 37 accessibility_view_(NULL), | |
| 38 caps_lock_view_(NULL), | |
| 39 clock_view_(NULL), | |
| 40 input_method_view_(NULL), | |
| 41 memory_view_(NULL), | |
| 42 network_view_(NULL), | |
| 43 power_view_(NULL), | |
| 44 need_return_focus_(false) { | |
| 45 } | 34 } |
| 46 | 35 |
| 47 StatusAreaView::~StatusAreaView() { | 36 StatusAreaView::~StatusAreaView() { |
| 48 } | 37 } |
| 49 | 38 |
| 50 void StatusAreaView::Init() { | 39 void StatusAreaView::AddButton(StatusAreaButton* button, bool bordered) { |
| 51 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryWidget)) { | 40 buttons_.push_back(button); |
| 52 memory_view_ = new MemoryMenuButton(host_); | 41 if (bordered) |
| 53 AddChildView(memory_view_); | 42 button->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0)); |
| 54 } | 43 AddChildView(button); |
| 44 } |
| 55 | 45 |
| 56 accessibility_view_ = new AccessibilityMenuButton(host_); | 46 // views::View* overrides. |
| 57 accessibility_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0)); | |
| 58 AddChildView(accessibility_view_); | |
| 59 | |
| 60 caps_lock_view_ = new CapsLockMenuButton(host_); | |
| 61 caps_lock_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0)); | |
| 62 AddChildView(caps_lock_view_); | |
| 63 | |
| 64 clock_view_ = new ClockMenuButton(host_); | |
| 65 clock_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0)); | |
| 66 AddChildView(clock_view_); | |
| 67 | |
| 68 input_method_view_ = new InputMethodMenuButton(host_); | |
| 69 AddChildView(input_method_view_); | |
| 70 | |
| 71 network_view_ = new NetworkMenuButton(host_); | |
| 72 AddChildView(network_view_); | |
| 73 | |
| 74 power_view_ = new PowerMenuButton(host_); | |
| 75 AddChildView(power_view_); | |
| 76 } | |
| 77 | 47 |
| 78 gfx::Size StatusAreaView::GetPreferredSize() { | 48 gfx::Size StatusAreaView::GetPreferredSize() { |
| 79 int result_w = 0; | 49 int result_w = 0; |
| 80 int result_h = 0; | 50 int result_h = 0; |
| 81 | 51 |
| 82 for (int i = 0; i < child_count(); i++) { | 52 for (int i = 0; i < child_count(); i++) { |
| 83 views::View* cur = child_at(i); | 53 views::View* cur = child_at(i); |
| 84 gfx::Size cur_size = cur->GetPreferredSize(); | 54 gfx::Size cur_size = cur->GetPreferredSize(); |
| 85 if (cur->IsVisible() && !cur_size.IsEmpty()) { | 55 if (cur->IsVisible() && !cur_size.IsEmpty()) { |
| 86 if (result_w == 0) | 56 if (result_w == 0) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 115 | 85 |
| 116 void StatusAreaView::ChildPreferredSizeChanged(View* child) { | 86 void StatusAreaView::ChildPreferredSizeChanged(View* child) { |
| 117 // When something like the clock menu button's size changes, we need to | 87 // When something like the clock menu button's size changes, we need to |
| 118 // relayout. Also mark that this view's size has changed. This will let | 88 // relayout. Also mark that this view's size has changed. This will let |
| 119 // BrowserView know to relayout, which will reset the bounds of this view. | 89 // BrowserView know to relayout, which will reset the bounds of this view. |
| 120 Layout(); | 90 Layout(); |
| 121 PreferredSizeChanged(); | 91 PreferredSizeChanged(); |
| 122 } | 92 } |
| 123 | 93 |
| 124 void StatusAreaView::MakeButtonsActive(bool active) { | 94 void StatusAreaView::MakeButtonsActive(bool active) { |
| 125 if (memory_view_) | 95 for (std::vector<StatusAreaButton*>::iterator iter = buttons_.begin(); |
| 126 memory_view_->set_active(active); | 96 iter != buttons_.end(); ++iter) { |
| 127 accessibility_view()->set_active(active); | 97 (*iter)->set_menu_active(active); |
| 128 caps_lock_view()->set_active(active); | 98 } |
| 129 clock_view()->set_active(active); | |
| 130 input_method_view()->set_active(active); | |
| 131 network_view()->set_active(active); | |
| 132 power_view()->set_active(active); | |
| 133 } | 99 } |
| 134 | 100 |
| 135 void StatusAreaView::ButtonVisibilityChanged(views::View* button_view) { | 101 void StatusAreaView::UpdateButtonVisibility() { |
| 136 Layout(); | 102 Layout(); |
| 137 PreferredSizeChanged(); | 103 PreferredSizeChanged(); |
| 138 } | 104 } |
| 139 | 105 |
| 140 void StatusAreaView::TakeFocus( | 106 void StatusAreaView::TakeFocus( |
| 141 bool reverse, | 107 bool reverse, |
| 142 const ReturnFocusCallback& return_focus_cb) { | 108 const ReturnFocusCallback& return_focus_cb) { |
| 143 // Emulates focus receive by AccessiblePaneView::SetPaneFocus. | 109 // Emulates focus receive by AccessiblePaneView::SetPaneFocus. |
| 144 if (!focus_manager_) | 110 if (!focus_manager_) |
| 145 focus_manager_ = GetFocusManager(); | 111 focus_manager_ = GetFocusManager(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 172 const views::View* first = GetFirstFocusableChild(); | 138 const views::View* first = GetFirstFocusableChild(); |
| 173 const views::View* last = GetLastFocusableChild(); | 139 const views::View* last = GetLastFocusableChild(); |
| 174 const bool first_to_last = (focused_before == first && focused_now == last); | 140 const bool first_to_last = (focused_before == first && focused_now == last); |
| 175 const bool last_to_first = (focused_now == first && focused_before == last); | 141 const bool last_to_first = (focused_now == first && focused_before == last); |
| 176 | 142 |
| 177 if (first_to_last || last_to_first) | 143 if (first_to_last || last_to_first) |
| 178 MessageLoop::current()->PostTask(FROM_HERE, | 144 MessageLoop::current()->PostTask(FROM_HERE, |
| 179 base::Bind(&StatusAreaView::ReturnFocus, AsWeakPtr(), first_to_last)); | 145 base::Bind(&StatusAreaView::ReturnFocus, AsWeakPtr(), first_to_last)); |
| 180 } | 146 } |
| 181 } | 147 } |
| 182 | |
| 183 } // namespace chromeos | |
| OLD | NEW |