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/setting_level_bubble.h" | 5 #include "chrome/browser/chromeos/setting_level_bubble.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/chromeos/login/background_view.h" | 9 #include "chrome/browser/chromeos/login/background_view.h" |
10 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 10 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 const int kAnimationIntervalMs = 1000 / 50; | 52 const int kAnimationIntervalMs = 1000 / 50; |
53 | 53 |
54 double LimitPercent(double percent) { | 54 double LimitPercent(double percent) { |
55 return min(max(percent, 0.0), 100.0); | 55 return min(max(percent, 0.0), 100.0); |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 namespace chromeos { | 60 namespace chromeos { |
61 | 61 |
62 // Temporary helper routine. Tries to first return the widget from the | |
63 // most-recently-focused normal browser window, then from a login | |
64 // background, and finally NULL if both of those fail. | |
65 // TODO(glotov): remove this in favor of enabling Bubble class act | |
66 // without |parent| specified. crosbug.com/4025 | |
67 static views::Widget* GetToplevelWidget() { | |
68 gfx::NativeWindow window = NULL; | |
69 | |
70 // We just use the default profile here -- this gets overridden as needed | |
71 // in Chrome OS depending on whether the user is logged in or not. | |
72 Browser* browser = | |
73 BrowserList::FindTabbedBrowser( | |
74 ProfileManager::GetDefaultProfile(), | |
75 true); // match_incognito | |
76 if (browser) { | |
77 window = browser->window()->GetNativeHandle(); | |
78 } else { | |
79 #if defined(USE_AURA) | |
80 // TODO(saintlou): Unsure what to do for the Aura background. | |
81 #else | |
82 // Otherwise, see if there's a background window that we can use. | |
83 BackgroundView* background = LoginUtils::Get()->GetBackgroundView(); | |
84 if (background) { | |
85 window = GTK_WINDOW(background->GetNativeWindow()); | |
86 } else { | |
87 LoginDisplayHost* host = BaseLoginDisplayHost::default_host(); | |
88 if (host) | |
89 window = host->GetNativeWindow(); | |
90 } | |
91 #endif | |
92 } | |
93 | |
94 if (window) { | |
95 return views::Widget::GetWidgetForNativeWindow(window); | |
96 } else { | |
97 NOTREACHED(); | |
98 return NULL; | |
99 } | |
100 } | |
101 | |
102 // SettingLevelBubbleDelegateView ---------------------------------------------- | 62 // SettingLevelBubbleDelegateView ---------------------------------------------- |
103 class SettingLevelBubbleDelegateView : public views::BubbleDelegateView { | 63 class SettingLevelBubbleDelegateView : public views::BubbleDelegateView { |
104 public: | 64 public: |
105 // BubbleDelegate overrides: | 65 // BubbleDelegate overrides: |
106 virtual gfx::Point GetAnchorPoint() OVERRIDE; | 66 virtual gfx::Point GetAnchorPoint() OVERRIDE; |
107 | 67 |
108 // Create the bubble delegate view. | 68 // Create the bubble delegate view. |
109 explicit SettingLevelBubbleDelegateView(views::Widget* parent); | 69 SettingLevelBubbleDelegateView(); |
110 virtual ~SettingLevelBubbleDelegateView(); | 70 virtual ~SettingLevelBubbleDelegateView(); |
111 | 71 |
112 SettingLevelBubbleView* view() { return view_; } | 72 SettingLevelBubbleView* view() { return view_; } |
113 | 73 |
114 protected: | 74 protected: |
115 // BubbleDelegate overrides: | 75 // BubbleDelegate overrides: |
116 virtual void Init() OVERRIDE; | 76 virtual void Init() OVERRIDE; |
117 | 77 |
118 private: | 78 private: |
119 views::Widget* parent_; | |
120 | |
121 SettingLevelBubbleView* view_; | 79 SettingLevelBubbleView* view_; |
122 | 80 |
123 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleDelegateView); | 81 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleDelegateView); |
124 }; | 82 }; |
125 | 83 |
126 gfx::Point SettingLevelBubbleDelegateView::GetAnchorPoint() { | 84 gfx::Point SettingLevelBubbleDelegateView::GetAnchorPoint() { |
127 gfx::Size view_size = GetPreferredSize(); | 85 gfx::Size view_size = GetPreferredSize(); |
128 // Calculate the position in screen coordinates that the bubble should | 86 // Calculate the position in screen coordinates that the bubble should |
129 // "point" at (since we use BubbleBorder::FLOAT, this position actually | 87 // "point" at (since we use BubbleBorder::FLOAT, this position actually |
130 // specifies the center of the bubble). | 88 // specifies the center of the bubble). |
131 gfx::Rect monitor_area = | 89 gfx::Rect monitor_area = gfx::Screen::GetMonitorAreaNearestWindow(NULL); |
132 gfx::Screen::GetMonitorAreaNearestWindow( | |
133 parent_->GetNativeView()); | |
134 return (gfx::Point( | 90 return (gfx::Point( |
135 monitor_area.x() + kBubbleXRatio * monitor_area.width(), | 91 monitor_area.x() + kBubbleXRatio * monitor_area.width(), |
136 monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap)); | 92 monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap)); |
137 } | 93 } |
138 | 94 |
139 SettingLevelBubbleDelegateView::SettingLevelBubbleDelegateView( | 95 SettingLevelBubbleDelegateView::SettingLevelBubbleDelegateView() |
140 views::Widget* parent) | |
141 : BubbleDelegateView(NULL, views::BubbleBorder::FLOAT, SK_ColorWHITE), | 96 : BubbleDelegateView(NULL, views::BubbleBorder::FLOAT, SK_ColorWHITE), |
142 parent_(parent), | |
143 view_(NULL) { | 97 view_(NULL) { |
144 set_close_on_esc(false); | 98 set_close_on_esc(false); |
145 set_use_focusless(true); | 99 set_use_focusless(true); |
146 } | 100 } |
147 | 101 |
148 SettingLevelBubbleDelegateView::~SettingLevelBubbleDelegateView() { | 102 SettingLevelBubbleDelegateView::~SettingLevelBubbleDelegateView() { |
149 view_ = NULL; | 103 view_ = NULL; |
150 } | 104 } |
151 | 105 |
152 void SettingLevelBubbleDelegateView::Init() { | 106 void SettingLevelBubbleDelegateView::Init() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // Update states. | 180 // Update states. |
227 current_percent_ = target_percent_; | 181 current_percent_ = target_percent_; |
228 target_time_ = TimeTicks(); | 182 target_time_ = TimeTicks(); |
229 last_animation_update_time_ = TimeTicks(); | 183 last_animation_update_time_ = TimeTicks(); |
230 last_target_update_time_ = TimeTicks(); | 184 last_target_update_time_ = TimeTicks(); |
231 hide_timer_.Stop(); | 185 hide_timer_.Stop(); |
232 StopAnimation(); | 186 StopAnimation(); |
233 } | 187 } |
234 | 188 |
235 SettingLevelBubbleView* SettingLevelBubble::CreateView() { | 189 SettingLevelBubbleView* SettingLevelBubble::CreateView() { |
236 views::Widget* parent = GetToplevelWidget(); | 190 SettingLevelBubbleDelegateView* delegate = new SettingLevelBubbleDelegateView; |
237 SettingLevelBubbleDelegateView* delegate = | |
238 new SettingLevelBubbleDelegateView(parent); | |
239 views::Widget* widget = views::BubbleDelegateView::CreateBubble(delegate); | 191 views::Widget* widget = views::BubbleDelegateView::CreateBubble(delegate); |
240 widget->AddObserver(this); | 192 widget->AddObserver(this); |
241 | 193 |
242 #if !defined(USE_AURA) | 194 #if !defined(USE_AURA) |
243 { | 195 { |
244 // TODO(alicet): Move this code to bubble_delegate_view.cc | |
245 // and add description on what this code does. | |
246 std::vector<int> params; | 196 std::vector<int> params; |
247 params.push_back(1); // show_while_screen_is_locked_ | 197 params.push_back(1); // show_while_screen_is_locked_ |
248 chromeos::WmIpc::instance()->SetWindowType( | 198 chromeos::WmIpc::instance()->SetWindowType( |
249 widget->GetNativeView(), | 199 widget->GetNativeView(), |
250 chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE, | 200 chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE, |
251 ¶ms); | 201 ¶ms); |
252 } | 202 } |
253 #endif | 203 #endif |
254 | 204 |
255 // Hold on to the content view. | 205 // Hold on to the content view. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 271 |
322 last_target_update_time_ = now; | 272 last_target_update_time_ = now; |
323 } | 273 } |
324 | 274 |
325 void SettingLevelBubble::StopAnimation() { | 275 void SettingLevelBubble::StopAnimation() { |
326 animation_timer_.Stop(); | 276 animation_timer_.Stop(); |
327 is_animating_ = false; | 277 is_animating_ = false; |
328 } | 278 } |
329 | 279 |
330 } // namespace chromeos | 280 } // namespace chromeos |
OLD | NEW |