OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/notifications/balloon_collection_impl.h" | 5 #include "chrome/browser/notifications/balloon_collection_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/notifications/balloon.h" | 10 #include "chrome/browser/notifications/balloon.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 int type, | 179 int type, |
180 const content::NotificationSource& source, | 180 const content::NotificationSource& source, |
181 const content::NotificationDetails& details) { | 181 const content::NotificationDetails& details) { |
182 gfx::Rect bounds; | 182 gfx::Rect bounds; |
183 switch (type) { | 183 switch (type) { |
184 case chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS: | 184 case chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS: |
185 bounds = content::Source<Panel>(source).ptr()->GetBounds(); | 185 bounds = content::Source<Panel>(source).ptr()->GetBounds(); |
186 // Fall through. | 186 // Fall through. |
187 case chrome::NOTIFICATION_PANEL_ADDED: | 187 case chrome::NOTIFICATION_PANEL_ADDED: |
188 case chrome::NOTIFICATION_PANEL_CLOSED: | 188 case chrome::NOTIFICATION_PANEL_CLOSED: |
189 layout_.enable_panel_offset(); | |
189 if (layout_.ComputeOffsetToMoveAbovePanels(bounds)) | 190 if (layout_.ComputeOffsetToMoveAbovePanels(bounds)) |
190 PositionBalloons(true); | 191 PositionBalloons(true); |
191 break; | 192 break; |
192 default: | 193 default: |
193 NOTREACHED(); | 194 NOTREACHED(); |
194 break; | 195 break; |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) { | 199 void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 } | 269 } |
269 } else { | 270 } else { |
270 // Mouse moved back into the region. Cancel the reposition. | 271 // Mouse moved back into the region. Cancel the reposition. |
271 reposition_factory_.InvalidateWeakPtrs(); | 272 reposition_factory_.InvalidateWeakPtrs(); |
272 } | 273 } |
273 } | 274 } |
274 #endif | 275 #endif |
275 | 276 |
276 BalloonCollectionImpl::Layout::Layout() | 277 BalloonCollectionImpl::Layout::Layout() |
277 : placement_(INVALID), | 278 : placement_(INVALID), |
279 panel_offset_enabled_(false), | |
278 offset_to_move_above_panels_(0) { | 280 offset_to_move_above_panels_(0) { |
279 RefreshSystemMetrics(); | 281 RefreshSystemMetrics(); |
280 } | 282 } |
281 | 283 |
282 void BalloonCollectionImpl::Layout::GetMaxLinearSize(int* max_balloon_size, | 284 void BalloonCollectionImpl::Layout::GetMaxLinearSize(int* max_balloon_size, |
283 int* total_size) const { | 285 int* total_size) const { |
284 DCHECK(max_balloon_size && total_size); | 286 DCHECK(max_balloon_size && total_size); |
285 | 287 |
286 // All placement schemes are vertical, so we only care about height. | 288 // All placement schemes are vertical, so we only care about height. |
287 *total_size = work_area_.height(); | 289 *total_size = work_area_.height(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 // restrict to the min & max sizes | 401 // restrict to the min & max sizes |
400 return gfx::Size( | 402 return gfx::Size( |
401 std::max(min_balloon_width(), | 403 std::max(min_balloon_width(), |
402 std::min(max_balloon_width(), size.width())), | 404 std::min(max_balloon_width(), size.width())), |
403 std::max(min_balloon_height(), | 405 std::max(min_balloon_height(), |
404 std::min(max_balloon_height(), size.height()))); | 406 std::min(max_balloon_height(), size.height()))); |
405 } | 407 } |
406 | 408 |
407 bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels( | 409 bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels( |
408 const gfx::Rect& panel_bounds) { | 410 const gfx::Rect& panel_bounds) { |
411 // If the offset is not enabled due to that we have not received a | |
412 // notification about panel, don't proceed because we don't want to call | |
413 // PanelManager::GetInstance() to create an instance when panel is not | |
414 // present. | |
415 if (!panel_offset_enabled_) | |
jennb
2012/03/08 04:34:18
Does BalloonCollection always exist? No chance of
jianli
2012/03/08 18:26:45
BalloonCollection is created when Chrome is starte
| |
416 return false; | |
417 | |
409 const DockedPanelStrip::Panels& panels = | 418 const DockedPanelStrip::Panels& panels = |
410 PanelManager::GetInstance()->docked_strip()->panels(); | 419 PanelManager::GetInstance()->docked_strip()->panels(); |
411 int offset_to_move_above_panels = 0; | 420 int offset_to_move_above_panels = 0; |
412 | 421 |
413 // The offset is the maximum height of panels that could overlap with the | 422 // The offset is the maximum height of panels that could overlap with the |
414 // balloons. | 423 // balloons. |
415 if (NeedToMoveAboveLeftSidePanels()) { | 424 if (NeedToMoveAboveLeftSidePanels()) { |
416 // If the affecting panel does not lie in the balloon area, no need to | 425 // If the affecting panel does not lie in the balloon area, no need to |
417 // update the offset. | 426 // update the offset. |
418 if (!panel_bounds.IsEmpty() && | 427 if (!panel_bounds.IsEmpty() && |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 gfx::Rect new_work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 486 gfx::Rect new_work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); |
478 #endif | 487 #endif |
479 if (!work_area_.Equals(new_work_area)) { | 488 if (!work_area_.Equals(new_work_area)) { |
480 work_area_.SetRect(new_work_area.x(), new_work_area.y(), | 489 work_area_.SetRect(new_work_area.x(), new_work_area.y(), |
481 new_work_area.width(), new_work_area.height()); | 490 new_work_area.width(), new_work_area.height()); |
482 changed = true; | 491 changed = true; |
483 } | 492 } |
484 | 493 |
485 return changed; | 494 return changed; |
486 } | 495 } |
OLD | NEW |