| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/status/clock_menu_button.h" | 9 #include "chrome/browser/chromeos/status/clock_menu_button.h" |
| 10 #include "chrome/browser/chromeos/status/language_menu_button.h" | 10 #include "chrome/browser/chromeos/status/language_menu_button.h" |
| 11 #include "chrome/browser/chromeos/status/network_menu_button.h" | 11 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 12 #include "chrome/browser/chromeos/status/power_menu_button.h" | 12 #include "chrome/browser/chromeos/status/power_menu_button.h" |
| 13 #include "chrome/browser/chromeos/status/status_area_host.h" | 13 #include "chrome/browser/chromeos/status/status_area_host.h" |
| 14 #include "gfx/canvas.h" | 14 #include "gfx/canvas.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 // Number of pixels to pad on the left border. | 18 // Number of pixels to separate each icon. |
| 19 const int kLeftBorder = 1; | 19 const int kSeparation = 6; |
| 20 // Number of pixels to separate the clock from the next item on the right. | |
| 21 const int kClockSeparation = 4; | |
| 22 // Number of pixels to separate the language selector from the next item | |
| 23 // on the right. | |
| 24 const int kLanguageSeparation = 4; | |
| 25 | 20 |
| 26 // BrowserWindowGtk tiles its image with this offset | 21 // BrowserWindowGtk tiles its image with this offset |
| 27 const int kCustomFrameBackgroundVerticalOffset = 15; | 22 const int kCustomFrameBackgroundVerticalOffset = 15; |
| 28 | 23 |
| 29 // Default to opening new tabs on the left. | 24 // Default to opening new tabs on the left. |
| 30 StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ = | 25 StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ = |
| 31 StatusAreaView::OPEN_TABS_ON_LEFT; | 26 StatusAreaView::OPEN_TABS_ON_LEFT; |
| 32 | 27 |
| 33 StatusAreaView::StatusAreaView(StatusAreaHost* host) | 28 StatusAreaView::StatusAreaView(StatusAreaHost* host) |
| 34 : host_(host), | 29 : host_(host), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 } | 52 } |
| 58 | 53 |
| 59 void StatusAreaView::Update() { | 54 void StatusAreaView::Update() { |
| 60 for (int i = 0; i < GetChildViewCount(); ++i) { | 55 for (int i = 0; i < GetChildViewCount(); ++i) { |
| 61 views::View* cur = GetChildViewAt(i); | 56 views::View* cur = GetChildViewAt(i); |
| 62 cur->SetVisible(host_->IsButtonVisible(cur)); | 57 cur->SetVisible(host_->IsButtonVisible(cur)); |
| 63 } | 58 } |
| 64 } | 59 } |
| 65 | 60 |
| 66 gfx::Size StatusAreaView::GetPreferredSize() { | 61 gfx::Size StatusAreaView::GetPreferredSize() { |
| 67 // Start with padding. | 62 int result_w = kSeparation; |
| 68 int result_w = kLeftBorder + kClockSeparation + kLanguageSeparation; | |
| 69 int result_h = 0; | 63 int result_h = 0; |
| 70 for (int i = 0; i < GetChildViewCount(); i++) { | 64 for (int i = 0; i < GetChildViewCount(); i++) { |
| 71 views::View* cur = GetChildViewAt(i); | 65 views::View* cur = GetChildViewAt(i); |
| 72 if (cur->IsVisible()) { | 66 if (cur->IsVisible()) { |
| 73 gfx::Size cur_size = cur->GetPreferredSize(); | 67 gfx::Size cur_size = cur->GetPreferredSize(); |
| 74 // Add each width. | 68 // Add each width. |
| 75 result_w += cur_size.width(); | 69 result_w += cur_size.width() + kSeparation; |
| 76 // Use max height. | 70 // Use max height. |
| 77 result_h = std::max(result_h, cur_size.height()); | 71 result_h = std::max(result_h, cur_size.height()); |
| 78 } | 72 } |
| 79 } | 73 } |
| 80 return gfx::Size(result_w, result_h); | 74 return gfx::Size(result_w, result_h); |
| 81 } | 75 } |
| 82 | 76 |
| 83 void StatusAreaView::Layout() { | 77 void StatusAreaView::Layout() { |
| 84 int cur_x = kLeftBorder; | 78 int cur_x = kSeparation; |
| 85 for (int i = 0; i < GetChildViewCount(); i++) { | 79 for (int i = 0; i < GetChildViewCount(); i++) { |
| 86 views::View* cur = GetChildViewAt(i); | 80 views::View* cur = GetChildViewAt(i); |
| 87 if (cur->IsVisible()) { | 81 if (cur->IsVisible()) { |
| 88 gfx::Size cur_size = cur->GetPreferredSize(); | 82 gfx::Size cur_size = cur->GetPreferredSize(); |
| 89 int cur_y = (height() - cur_size.height()) / 2; | 83 int cur_y = (height() - cur_size.height()) / 2; |
| 90 | 84 |
| 91 // Handle odd number of pixels. | 85 // Handle odd number of pixels. |
| 92 cur_y += (height() - cur_size.height()) % 2; | 86 cur_y += (height() - cur_size.height()) % 2; |
| 93 | 87 |
| 94 // Put next in row horizontally, and center vertically. | 88 // Put next in row horizontally, and center vertically. |
| 95 cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height()); | 89 cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height()); |
| 96 | 90 |
| 97 cur_x += cur_size.width(); | 91 cur_x += cur_size.width() + kSeparation; |
| 98 | |
| 99 // Buttons have built in padding, but clock and language status don't. | |
| 100 if (cur == clock_view_) | |
| 101 cur_x += kClockSeparation; | |
| 102 else if (cur == language_view_) | |
| 103 cur_x += kLanguageSeparation; | |
| 104 } | 92 } |
| 105 } | 93 } |
| 106 } | 94 } |
| 107 | 95 |
| 96 void StatusAreaView::ChildPreferredSizeChanged(View* child) { |
| 97 // When something like the clock menu button's size changes, we need to |
| 98 // relayout. Also mark that this view's size has changed. This will let |
| 99 // BrowserView know to relayout, which will reset the bounds of this view. |
| 100 Layout(); |
| 101 PreferredSizeChanged(); |
| 102 } |
| 103 |
| 108 // static | 104 // static |
| 109 StatusAreaView::OpenTabsMode StatusAreaView::GetOpenTabsMode() { | 105 StatusAreaView::OpenTabsMode StatusAreaView::GetOpenTabsMode() { |
| 110 return open_tabs_mode_; | 106 return open_tabs_mode_; |
| 111 } | 107 } |
| 112 | 108 |
| 113 // static | 109 // static |
| 114 void StatusAreaView::SetOpenTabsMode(OpenTabsMode mode) { | 110 void StatusAreaView::SetOpenTabsMode(OpenTabsMode mode) { |
| 115 open_tabs_mode_ = mode; | 111 open_tabs_mode_ = mode; |
| 116 } | 112 } |
| 117 | 113 |
| 118 } // namespace chromeos | 114 } // namespace chromeos |
| OLD | NEW |