| 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 // Draws the view for the balloons. | 5 // Draws the view for the balloons. |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/notifications/notification_panel.h" | 7 #include "chrome/browser/chromeos/notifications/notification_panel.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 virtual ~BalloonSubContainer() {} | 163 virtual ~BalloonSubContainer() {} |
| 164 | 164 |
| 165 // views::View overrides. | 165 // views::View overrides. |
| 166 virtual gfx::Size GetPreferredSize() { | 166 virtual gfx::Size GetPreferredSize() { |
| 167 return preferred_size_; | 167 return preferred_size_; |
| 168 } | 168 } |
| 169 | 169 |
| 170 virtual void Layout() { | 170 virtual void Layout() { |
| 171 // Layout bottom up | 171 // Layout bottom up |
| 172 int height = 0; | 172 int height = 0; |
| 173 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 173 for (int i = child_count() - 1; i >= 0; --i) { |
| 174 views::View* child = GetChildViewAt(i); | 174 views::View* child = GetChildViewAt(i); |
| 175 child->SetBounds(0, height, child->width(), child->height()); | 175 child->SetBounds(0, height, child->width(), child->height()); |
| 176 height += child->height() + margin_; | 176 height += child->height() + margin_; |
| 177 } | 177 } |
| 178 SchedulePaint(); | 178 SchedulePaint(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Updates the bound so that it can show all balloons. | 181 // Updates the bound so that it can show all balloons. |
| 182 void UpdateBounds() { | 182 void UpdateBounds() { |
| 183 int height = 0; | 183 int height = 0; |
| 184 int max_width = 0; | 184 int max_width = 0; |
| 185 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 185 for (int i = child_count() - 1; i >= 0; --i) { |
| 186 views::View* child = GetChildViewAt(i); | 186 views::View* child = GetChildViewAt(i); |
| 187 height += child->height() + margin_; | 187 height += child->height() + margin_; |
| 188 max_width = std::max(max_width, child->width()); | 188 max_width = std::max(max_width, child->width()); |
| 189 } | 189 } |
| 190 if (height > 0) | 190 if (height > 0) |
| 191 height -= margin_; | 191 height -= margin_; |
| 192 preferred_size_.set_width(max_width); | 192 preferred_size_.set_width(max_width); |
| 193 preferred_size_.set_height(height); | 193 preferred_size_.set_height(height); |
| 194 SizeToPreferredSize(); | 194 SizeToPreferredSize(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Returns the bounds that covers new notifications. | 197 // Returns the bounds that covers new notifications. |
| 198 gfx::Rect GetNewBounds() { | 198 gfx::Rect GetNewBounds() { |
| 199 gfx::Rect rect; | 199 gfx::Rect rect; |
| 200 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 200 for (int i = child_count() - 1; i >= 0; --i) { |
| 201 BalloonViewImpl* view = | 201 BalloonViewImpl* view = |
| 202 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); | 202 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); |
| 203 if (!view->stale()) { | 203 if (!view->stale()) { |
| 204 if (rect.IsEmpty()) { | 204 if (rect.IsEmpty()) { |
| 205 rect = view->bounds(); | 205 rect = view->bounds(); |
| 206 } else { | 206 } else { |
| 207 rect = rect.Union(view->bounds()); | 207 rect = rect.Union(view->bounds()); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 return gfx::Rect(x(), y(), rect.width(), rect.height()); | 211 return gfx::Rect(x(), y(), rect.width(), rect.height()); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Returns # of new notifications. | 214 // Returns # of new notifications. |
| 215 int GetNewCount() { | 215 int GetNewCount() { |
| 216 int count = 0; | 216 int count = 0; |
| 217 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 217 for (int i = child_count() - 1; i >= 0; --i) { |
| 218 BalloonViewImpl* view = | 218 BalloonViewImpl* view = |
| 219 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); | 219 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); |
| 220 if (!view->stale()) | 220 if (!view->stale()) |
| 221 count++; | 221 count++; |
| 222 } | 222 } |
| 223 return count; | 223 return count; |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Make all notifications stale. | 226 // Make all notifications stale. |
| 227 void MakeAllStale() { | 227 void MakeAllStale() { |
| 228 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 228 for (int i = child_count() - 1; i >= 0; --i) { |
| 229 BalloonViewImpl* view = | 229 BalloonViewImpl* view = |
| 230 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); | 230 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); |
| 231 view->set_stale(); | 231 view->set_stale(); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 void DismissAll() { | 235 void DismissAll() { |
| 236 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 236 for (int i = child_count() - 1; i >= 0; --i) { |
| 237 BalloonViewImpl* view = | 237 BalloonViewImpl* view = |
| 238 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); | 238 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); |
| 239 view->Close(true); | 239 view->Close(true); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 BalloonViewImpl* FindBalloonView(const Notification& notification) { | 243 BalloonViewImpl* FindBalloonView(const Notification& notification) { |
| 244 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 244 for (int i = child_count() - 1; i >= 0; --i) { |
| 245 BalloonViewImpl* view = | 245 BalloonViewImpl* view = |
| 246 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); | 246 static_cast<BalloonViewImpl*>(GetChildViewAt(i)); |
| 247 if (view->IsFor(notification)) { | 247 if (view->IsFor(notification)) { |
| 248 return view; | 248 return view; |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 return NULL; | 251 return NULL; |
| 252 } | 252 } |
| 253 | 253 |
| 254 BalloonViewImpl* FindBalloonView(const gfx::Point point) { | 254 BalloonViewImpl* FindBalloonView(const gfx::Point point) { |
| 255 gfx::Point copy(point); | 255 gfx::Point copy(point); |
| 256 ConvertPointFromWidget(this, ©); | 256 ConvertPointFromWidget(this, ©); |
| 257 for (int i = GetChildViewCount() - 1; i >= 0; --i) { | 257 for (int i = child_count() - 1; i >= 0; --i) { |
| 258 views::View* view = GetChildViewAt(i); | 258 views::View* view = GetChildViewAt(i); |
| 259 if (view->bounds().Contains(copy)) | 259 if (view->bounds().Contains(copy)) |
| 260 return static_cast<BalloonViewImpl*>(view); | 260 return static_cast<BalloonViewImpl*>(view); |
| 261 } | 261 } |
| 262 return NULL; | 262 return NULL; |
| 263 } | 263 } |
| 264 | 264 |
| 265 private: | 265 private: |
| 266 gfx::Size preferred_size_; | 266 gfx::Size preferred_size_; |
| 267 int margin_; | 267 int margin_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 280 sticky_container_(new BalloonSubContainer(margin)), | 280 sticky_container_(new BalloonSubContainer(margin)), |
| 281 non_sticky_container_(new BalloonSubContainer(margin)) { | 281 non_sticky_container_(new BalloonSubContainer(margin)) { |
| 282 AddChildView(sticky_container_); | 282 AddChildView(sticky_container_); |
| 283 AddChildView(non_sticky_container_); | 283 AddChildView(non_sticky_container_); |
| 284 } | 284 } |
| 285 virtual ~BalloonContainer() {} | 285 virtual ~BalloonContainer() {} |
| 286 | 286 |
| 287 // views::View overrides. | 287 // views::View overrides. |
| 288 virtual void Layout() { | 288 virtual void Layout() { |
| 289 int margin = | 289 int margin = |
| 290 (sticky_container_->GetChildViewCount() != 0 && | 290 (sticky_container_->child_count() != 0 && |
| 291 non_sticky_container_->GetChildViewCount() != 0) ? | 291 non_sticky_container_->child_count() != 0) ? |
| 292 margin_ : 0; | 292 margin_ : 0; |
| 293 sticky_container_->SetBounds( | 293 sticky_container_->SetBounds( |
| 294 0, 0, width(), sticky_container_->height()); | 294 0, 0, width(), sticky_container_->height()); |
| 295 non_sticky_container_->SetBounds( | 295 non_sticky_container_->SetBounds( |
| 296 0, sticky_container_->bounds().bottom() + margin, | 296 0, sticky_container_->bounds().bottom() + margin, |
| 297 width(), non_sticky_container_->height()); | 297 width(), non_sticky_container_->height()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 virtual gfx::Size GetPreferredSize() { | 300 virtual gfx::Size GetPreferredSize() { |
| 301 return preferred_size_; | 301 return preferred_size_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 315 // Adds a ballon to the panel. | 315 // Adds a ballon to the panel. |
| 316 void Add(Balloon* balloon) { | 316 void Add(Balloon* balloon) { |
| 317 BalloonViewImpl* view = GetBalloonViewOf(balloon); | 317 BalloonViewImpl* view = GetBalloonViewOf(balloon); |
| 318 GetContainerFor(balloon)->AddChildView(view); | 318 GetContainerFor(balloon)->AddChildView(view); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // Updates the position of the |balloon|. | 321 // Updates the position of the |balloon|. |
| 322 bool Update(Balloon* balloon) { | 322 bool Update(Balloon* balloon) { |
| 323 BalloonViewImpl* view = GetBalloonViewOf(balloon); | 323 BalloonViewImpl* view = GetBalloonViewOf(balloon); |
| 324 View* container = NULL; | 324 View* container = NULL; |
| 325 if (sticky_container_->HasChildView(view)) { | 325 if (view->parent() == sticky_container_) { |
| 326 container = sticky_container_; | 326 container = sticky_container_; |
| 327 } else if (non_sticky_container_->HasChildView(view)) { | 327 } else if (view->parent() == non_sticky_container_) { |
| 328 container = non_sticky_container_; | 328 container = non_sticky_container_; |
| 329 } | 329 } |
| 330 if (container) { | 330 if (container) { |
| 331 container->RemoveChildView(view); | 331 container->RemoveChildView(view); |
| 332 container->AddChildView(view); | 332 container->AddChildView(view); |
| 333 return true; | 333 return true; |
| 334 } else { | 334 } else { |
| 335 return false; | 335 return false; |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Removes a ballon from the panel. | 339 // Removes a ballon from the panel. |
| 340 BalloonViewImpl* Remove(Balloon* balloon) { | 340 BalloonViewImpl* Remove(Balloon* balloon) { |
| 341 BalloonViewImpl* view = GetBalloonViewOf(balloon); | 341 BalloonViewImpl* view = GetBalloonViewOf(balloon); |
| 342 GetContainerFor(balloon)->RemoveChildView(view); | 342 GetContainerFor(balloon)->RemoveChildView(view); |
| 343 return view; | 343 return view; |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Returns the number of notifications added to the panel. | 346 // Returns the number of notifications added to the panel. |
| 347 int GetNotificationCount() { | 347 int GetNotificationCount() { |
| 348 return sticky_container_->GetChildViewCount() + | 348 return sticky_container_->child_count() + |
| 349 non_sticky_container_->GetChildViewCount(); | 349 non_sticky_container_->child_count(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 // Returns the # of new notifications. | 352 // Returns the # of new notifications. |
| 353 int GetNewNotificationCount() { | 353 int GetNewNotificationCount() { |
| 354 return sticky_container_->GetNewCount() + | 354 return sticky_container_->GetNewCount() + |
| 355 non_sticky_container_->GetNewCount(); | 355 non_sticky_container_->GetNewCount(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 // Returns the # of sticky and new notifications. | 358 // Returns the # of sticky and new notifications. |
| 359 int GetStickyNewNotificationCount() { | 359 int GetStickyNewNotificationCount() { |
| 360 return sticky_container_->GetChildViewCount() + | 360 return sticky_container_->child_count() + |
| 361 non_sticky_container_->GetNewCount(); | 361 non_sticky_container_->GetNewCount(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Returns the # of sticky notifications. | 364 // Returns the # of sticky notifications. |
| 365 int GetStickyNotificationCount() { | 365 int GetStickyNotificationCount() { |
| 366 return sticky_container_->GetChildViewCount(); | 366 return sticky_container_->child_count(); |
| 367 } | 367 } |
| 368 | 368 |
| 369 // Returns true if the |view| is contained in the panel. | 369 // Returns true if the |view| is contained in the panel. |
| 370 bool HasBalloonView(View* view) { | 370 bool HasBalloonView(View* view) { |
| 371 return sticky_container_->HasChildView(view) || | 371 return view->parent() == sticky_container_ || |
| 372 non_sticky_container_->HasChildView(view); | 372 view->parent() == non_sticky_container_; |
| 373 } | 373 } |
| 374 | 374 |
| 375 // Updates the bounds so that all notifications are visible. | 375 // Updates the bounds so that all notifications are visible. |
| 376 void UpdateBounds() { | 376 void UpdateBounds() { |
| 377 sticky_container_->UpdateBounds(); | 377 sticky_container_->UpdateBounds(); |
| 378 non_sticky_container_->UpdateBounds(); | 378 non_sticky_container_->UpdateBounds(); |
| 379 preferred_size_ = sticky_container_->GetPreferredSize(); | 379 preferred_size_ = sticky_container_->GetPreferredSize(); |
| 380 | 380 |
| 381 gfx::Size non_sticky_size = non_sticky_container_->GetPreferredSize(); | 381 gfx::Size non_sticky_size = non_sticky_container_->GetPreferredSize(); |
| 382 int margin = | 382 int margin = |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 &origin); | 868 &origin); |
| 869 return rect.Contains(gfx::Rect(origin, view->size())); | 869 return rect.Contains(gfx::Rect(origin, view->size())); |
| 870 } | 870 } |
| 871 | 871 |
| 872 | 872 |
| 873 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { | 873 bool NotificationPanelTester::IsActive(const BalloonViewImpl* view) const { |
| 874 return panel_->active_ == view; | 874 return panel_->active_ == view; |
| 875 } | 875 } |
| 876 | 876 |
| 877 } // namespace chromeos | 877 } // namespace chromeos |
| OLD | NEW |