| 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 "ash/system/tray/system_tray_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBackground); | 169 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBackground); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 class SystemTrayBubbleBorder : public views::BubbleBorder { | 172 class SystemTrayBubbleBorder : public views::BubbleBorder { |
| 173 public: | 173 public: |
| 174 enum ArrowType { | 174 enum ArrowType { |
| 175 ARROW_TYPE_NONE, | 175 ARROW_TYPE_NONE, |
| 176 ARROW_TYPE_BOTTOM, | 176 ARROW_TYPE_BOTTOM, |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 SystemTrayBubbleBorder(views::View* owner, ArrowType arrow_type) | 179 SystemTrayBubbleBorder(views::View* owner, |
| 180 ArrowType arrow_type, |
| 181 int arrow_offset) |
| 180 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, | 182 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, |
| 181 views::BubbleBorder::NO_SHADOW), | 183 views::BubbleBorder::NO_SHADOW), |
| 182 owner_(owner), | 184 owner_(owner), |
| 183 arrow_type_(arrow_type) { | 185 arrow_type_(arrow_type), |
| 186 arrow_offset_(arrow_offset) { |
| 184 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 187 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 185 } | 188 } |
| 186 | 189 |
| 187 virtual ~SystemTrayBubbleBorder() {} | 190 virtual ~SystemTrayBubbleBorder() {} |
| 188 | 191 |
| 189 private: | 192 private: |
| 190 // Overridden from views::Border. | 193 // Overridden from views::Border. |
| 191 virtual void Paint(const views::View& view, | 194 virtual void Paint(const views::View& view, |
| 192 gfx::Canvas* canvas) const OVERRIDE { | 195 gfx::Canvas* canvas) const OVERRIDE { |
| 193 gfx::Insets inset; | 196 gfx::Insets inset; |
| 194 GetInsets(&inset); | 197 GetInsets(&inset); |
| 195 DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(), | 198 DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(), |
| 196 inset); | 199 inset); |
| 197 | 200 |
| 198 // Draw the bottom line. | 201 // Draw the bottom line. |
| 199 int y = owner_->height() + 1; | 202 int y = owner_->height() + 1; |
| 200 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(), | 203 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(), |
| 201 kBottomLineHeight), kBorderDarkColor); | 204 kBottomLineHeight), kBorderDarkColor); |
| 202 | 205 |
| 203 if (!Shell::GetInstance()->shelf()->IsVisible()) | 206 if (!Shell::GetInstance()->shelf()->IsVisible()) |
| 204 return; | 207 return; |
| 205 | 208 |
| 206 // Draw the arrow. | 209 // Draw the arrow. |
| 207 if (arrow_type_ == ARROW_TYPE_BOTTOM) { | 210 if (arrow_type_ == ARROW_TYPE_BOTTOM) { |
| 208 int left_base_x = base::i18n::IsRTL() ? kArrowWidth : | 211 int tip_x = base::i18n::IsRTL() ? arrow_offset_ : |
| 209 owner_->width() - kArrowPaddingFromRight - kArrowWidth; | 212 owner_->width() - arrow_offset_; |
| 213 int left_base_x = tip_x - kArrowWidth / 2; |
| 210 int left_base_y = y; | 214 int left_base_y = y; |
| 211 int tip_x = left_base_x + kArrowWidth / 2; | |
| 212 int tip_y = left_base_y + kArrowHeight; | 215 int tip_y = left_base_y + kArrowHeight; |
| 216 |
| 213 SkPath path; | 217 SkPath path; |
| 214 path.incReserve(4); | 218 path.incReserve(4); |
| 215 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); | 219 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); |
| 216 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 220 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
| 217 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), | 221 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), |
| 218 SkIntToScalar(left_base_y)); | 222 SkIntToScalar(left_base_y)); |
| 219 | 223 |
| 220 SkPaint paint; | 224 SkPaint paint; |
| 221 paint.setStyle(SkPaint::kFill_Style); | 225 paint.setStyle(SkPaint::kFill_Style); |
| 222 paint.setColor(kHeaderBackgroundColorDark); | 226 paint.setColor(kHeaderBackgroundColorDark); |
| 223 canvas->DrawPath(path, paint); | 227 canvas->DrawPath(path, paint); |
| 224 | 228 |
| 225 // Now draw the arrow border. | 229 // Now draw the arrow border. |
| 226 paint.setStyle(SkPaint::kStroke_Style); | 230 paint.setStyle(SkPaint::kStroke_Style); |
| 227 paint.setColor(kBorderDarkColor); | 231 paint.setColor(kBorderDarkColor); |
| 228 canvas->DrawPath(path, paint); | 232 canvas->DrawPath(path, paint); |
| 229 } | 233 } |
| 230 } | 234 } |
| 231 | 235 |
| 232 views::View* owner_; | 236 views::View* owner_; |
| 233 ArrowType arrow_type_; | 237 ArrowType arrow_type_; |
| 238 const int arrow_offset_; |
| 234 | 239 |
| 235 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); | 240 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); |
| 236 }; | 241 }; |
| 237 | 242 |
| 238 } // namespace | 243 } // namespace |
| 239 | 244 |
| 240 namespace internal { | 245 namespace internal { |
| 241 | 246 |
| 242 // SystemTrayBubbleView | 247 // SystemTrayBubbleView |
| 243 | 248 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { | 319 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { |
| 315 if (host_) | 320 if (host_) |
| 316 host_->StopAutoCloseTimer(); | 321 host_->StopAutoCloseTimer(); |
| 317 } | 322 } |
| 318 | 323 |
| 319 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { | 324 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { |
| 320 if (host_) | 325 if (host_) |
| 321 host_->RestartAutoCloseTimer(); | 326 host_->RestartAutoCloseTimer(); |
| 322 } | 327 } |
| 323 | 328 |
| 329 // SystemTrayBubble::InitParams |
| 330 SystemTrayBubble::InitParams::InitParams( |
| 331 SystemTrayBubble::AnchorType anchor_type) |
| 332 : anchor(NULL), |
| 333 anchor_type(anchor_type), |
| 334 can_activate(false), |
| 335 login_status(ash::user::LOGGED_IN_NONE), |
| 336 arrow_offset(kArrowPaddingFromRight + kArrowWidth / 2) { |
| 337 } |
| 338 |
| 324 // SystemTrayBubble | 339 // SystemTrayBubble |
| 325 | 340 |
| 326 SystemTrayBubble::SystemTrayBubble( | 341 SystemTrayBubble::SystemTrayBubble( |
| 327 ash::SystemTray* tray, | 342 ash::SystemTray* tray, |
| 328 const std::vector<ash::SystemTrayItem*>& items, | 343 const std::vector<ash::SystemTrayItem*>& items, |
| 329 BubbleType bubble_type) | 344 BubbleType bubble_type) |
| 330 : tray_(tray), | 345 : tray_(tray), |
| 331 bubble_view_(NULL), | 346 bubble_view_(NULL), |
| 332 bubble_widget_(NULL), | 347 bubble_widget_(NULL), |
| 333 items_(items), | 348 items_(items), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 353 BubbleType bubble_type) { | 368 BubbleType bubble_type) { |
| 354 DestroyItemViews(); | 369 DestroyItemViews(); |
| 355 bubble_view_->RemoveAllChildViews(true); | 370 bubble_view_->RemoveAllChildViews(true); |
| 356 | 371 |
| 357 items_ = items; | 372 items_ = items; |
| 358 bubble_type_ = bubble_type; | 373 bubble_type_ = bubble_type; |
| 359 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); | 374 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); |
| 360 bubble_widget_->GetContentsView()->Layout(); | 375 bubble_widget_->GetContentsView()->Layout(); |
| 361 } | 376 } |
| 362 | 377 |
| 363 void SystemTrayBubble::InitView(views::View* anchor, | 378 void SystemTrayBubble::InitView(const InitParams& init_params) { |
| 364 AnchorType anchor_type, | |
| 365 bool can_activate, | |
| 366 ash::user::LoginStatus login_status) { | |
| 367 DCHECK(bubble_view_ == NULL); | 379 DCHECK(bubble_view_ == NULL); |
| 368 anchor_type_ = anchor_type; | 380 anchor_type_ = init_params.anchor_type; |
| 369 bubble_view_ = new SystemTrayBubbleView(anchor, this, can_activate); | 381 bubble_view_ = new SystemTrayBubbleView( |
| 382 init_params.anchor, this, init_params.can_activate); |
| 370 | 383 |
| 371 CreateItemViews(login_status); | 384 CreateItemViews(init_params.login_status); |
| 372 | 385 |
| 373 DCHECK(bubble_widget_ == NULL); | 386 DCHECK(bubble_widget_ == NULL); |
| 374 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | 387 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
| 375 | 388 |
| 376 // Must occur after call to CreateBubble() | 389 // Must occur after call to CreateBubble() |
| 377 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 390 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 378 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | 391 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
| 379 SystemTrayBubbleBorder::ArrowType arrow_type; | 392 SystemTrayBubbleBorder::ArrowType arrow_type; |
| 380 if (anchor_type_ == ANCHOR_TYPE_TRAY) | 393 if (anchor_type_ == ANCHOR_TYPE_TRAY) |
| 381 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM; | 394 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM; |
| 382 else | 395 else |
| 383 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_NONE; | 396 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_NONE; |
| 384 bubble_view_->SetBubbleBorder( | 397 |
| 385 new SystemTrayBubbleBorder(bubble_view_, arrow_type)); | 398 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( |
| 399 bubble_view_, arrow_type, init_params.arrow_offset); |
| 400 bubble_view_->SetBubbleBorder(bubble_border); |
| 386 | 401 |
| 387 bubble_widget_->AddObserver(this); | 402 bubble_widget_->AddObserver(this); |
| 388 | 403 |
| 389 // Setup animation. | 404 // Setup animation. |
| 390 ash::SetWindowVisibilityAnimationType( | 405 ash::SetWindowVisibilityAnimationType( |
| 391 bubble_widget_->GetNativeWindow(), | 406 bubble_widget_->GetNativeWindow(), |
| 392 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 407 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 393 ash::SetWindowVisibilityAnimationTransition( | 408 ash::SetWindowVisibilityAnimationTransition( |
| 394 bubble_widget_->GetNativeWindow(), | 409 bubble_widget_->GetNativeWindow(), |
| 395 ash::ANIMATE_BOTH); | 410 ash::ANIMATE_BOTH); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } | 501 } |
| 487 | 502 |
| 488 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { | 503 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { |
| 489 CHECK_EQ(bubble_widget_, widget); | 504 CHECK_EQ(bubble_widget_, widget); |
| 490 bubble_widget_ = NULL; | 505 bubble_widget_ = NULL; |
| 491 tray_->RemoveBubble(this); | 506 tray_->RemoveBubble(this); |
| 492 } | 507 } |
| 493 | 508 |
| 494 } // namespace internal | 509 } // namespace internal |
| 495 } // namespace ash | 510 } // namespace ash |
| OLD | NEW |