Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
| 28 #include "ui/views/layout/fill_layout.h" | 28 #include "ui/views/layout/fill_layout.h" |
| 29 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
| 30 | 30 |
| 31 namespace ash { | 31 namespace ash { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const int kShadowThickness = 4; | 35 const int kShadowThickness = 4; |
| 36 | 36 |
| 37 const int kLeftPadding = 4; | |
| 38 const int kBottomLineHeight = 1; | 37 const int kBottomLineHeight = 1; |
| 39 | 38 |
| 39 const int kSystemTrayBubbleHorizontalInset = 1; | |
| 40 const int kSystemTrayBubbleVerticalInset = 1; | |
| 41 | |
| 40 const int kArrowHeight = 10; | 42 const int kArrowHeight = 10; |
| 41 const int kArrowWidth = 20; | 43 const int kArrowWidth = 20; |
| 42 const int kArrowPaddingFromRight = 20; | 44 const int kArrowPaddingFromRight = 20; |
| 45 const int kMinArrowOffset = 12; | |
| 43 | 46 |
| 44 const int kAnimationDurationForPopupMS = 200; | 47 const int kAnimationDurationForPopupMS = 200; |
| 45 | 48 |
| 46 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); | 49 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); |
| 47 | 50 |
| 48 void DrawBlurredShadowAroundView(gfx::Canvas* canvas, | 51 void DrawBlurredShadowAroundView(gfx::Canvas* canvas, |
| 49 int top, | 52 int top, |
| 50 int bottom, | 53 int bottom, |
| 51 int width, | 54 int width, |
| 52 const gfx::Insets& inset) { | 55 const gfx::Insets& inset) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 canvas->FillRect(gfx::Rect(size()), | 124 canvas->FillRect(gfx::Rect(size()), |
| 122 hover_ ? kHoverBackgroundColor : kBackgroundColor); | 125 hover_ ? kHoverBackgroundColor : kBackgroundColor); |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool hover_; | 129 bool hover_; |
| 127 | 130 |
| 128 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); | 131 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); |
| 129 }; | 132 }; |
| 130 | 133 |
| 131 class SystemTrayBubbleBackground : public views::Background { | 134 class SystemTrayBubbleBorder : public views::BubbleBorder { |
| 132 public: | 135 public: |
| 133 explicit SystemTrayBubbleBackground(views::View* owner) | 136 SystemTrayBubbleBorder(views::View* owner, |
| 134 : owner_(owner) { | 137 views::BubbleBorder::ArrowLocation arrow_location, |
| 138 int arrow_offset) | |
| 139 : views::BubbleBorder(arrow_location, | |
| 140 views::BubbleBorder::NO_SHADOW), | |
| 141 owner_(owner), | |
| 142 arrow_offset_(std::max(arrow_offset, kMinArrowOffset)) { | |
| 143 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
| 135 } | 144 } |
| 136 | 145 |
| 137 virtual ~SystemTrayBubbleBackground() {} | 146 virtual ~SystemTrayBubbleBorder() {} |
| 138 | 147 |
| 139 private: | 148 private: |
| 140 // Overridden from views::Background. | 149 void PaintChildBorder(gfx::Canvas* canvas) const { |
| 141 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | 150 gfx::Insets insets; |
| 151 GetInsets(&insets); | |
| 152 canvas->Save(); | |
| 153 canvas->Translate(gfx::Point(insets.left(), insets.top())); | |
| 142 views::View* last_view = NULL; | 154 views::View* last_view = NULL; |
| 143 for (int i = 0; i < owner_->child_count(); i++) { | 155 for (int i = 0; i < owner_->child_count(); i++) { |
| 144 views::View* v = owner_->child_at(i); | 156 views::View* v = owner_->child_at(i); |
| 157 if (!v->visible()) | |
| 158 continue; | |
| 145 | 159 |
| 146 if (!v->border()) { | 160 if (!v->border()) { |
| 147 canvas->DrawLine(gfx::Point(v->x(), v->y() - 1), | 161 canvas->DrawLine(gfx::Point(v->x(), v->y() - 1), |
| 148 gfx::Point(v->x() + v->width(), v->y() - 1), | 162 gfx::Point(v->x() + v->width(), v->y() - 1), |
| 149 !last_view || last_view->border() ? kBorderDarkColor : | 163 !last_view || last_view->border() ? kBorderDarkColor : |
| 150 kBorderLightColor); | 164 kBorderLightColor); |
| 151 } else if (last_view && !last_view->border()) { | 165 } else if (last_view && !last_view->border()) { |
| 152 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), | 166 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), |
| 153 gfx::Point(v->x() + v->width() + 1, v->y() - 1), | 167 gfx::Point(v->x() + v->width() + 1, v->y() - 1), |
| 154 kBorderDarkColor); | 168 kBorderDarkColor); |
| 155 } | 169 } |
| 156 | 170 |
| 157 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), | 171 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), |
| 158 gfx::Point(v->x() - 1, v->y() + v->height() + 1), | 172 gfx::Point(v->x() - 1, v->y() + v->height() + 1), |
| 159 kBorderDarkColor); | 173 kBorderDarkColor); |
| 160 canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1), | 174 canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1), |
| 161 gfx::Point(v->x() + v->width(), v->y() + v->height() + 1), | 175 gfx::Point(v->x() + v->width(), v->y() + v->height() + 1), |
| 162 kBorderDarkColor); | 176 kBorderDarkColor); |
| 163 last_view = v; | 177 last_view = v; |
| 164 } | 178 } |
| 179 canvas->Restore(); | |
| 165 } | 180 } |
| 166 | 181 |
| 167 views::View* owner_; | |
| 168 | |
| 169 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBackground); | |
| 170 }; | |
| 171 | |
| 172 class SystemTrayBubbleBorder : public views::BubbleBorder { | |
| 173 public: | |
| 174 enum ArrowType { | |
| 175 ARROW_TYPE_NONE, | |
| 176 ARROW_TYPE_BOTTOM, | |
| 177 }; | |
| 178 | |
| 179 SystemTrayBubbleBorder(views::View* owner, | |
| 180 ArrowType arrow_type, | |
| 181 int arrow_offset) | |
| 182 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, | |
| 183 views::BubbleBorder::NO_SHADOW), | |
| 184 owner_(owner), | |
| 185 arrow_type_(arrow_type), | |
| 186 arrow_offset_(arrow_offset) { | |
| 187 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
| 188 } | |
| 189 | |
| 190 virtual ~SystemTrayBubbleBorder() {} | |
| 191 | |
| 192 private: | |
| 193 // Overridden from views::Border. | 182 // Overridden from views::Border. |
| 194 virtual void Paint(const views::View& view, | 183 virtual void Paint(const views::View& view, |
| 195 gfx::Canvas* canvas) const OVERRIDE { | 184 gfx::Canvas* canvas) const OVERRIDE { |
| 196 gfx::Insets inset; | 185 gfx::Insets inset; |
| 197 GetInsets(&inset); | 186 GetInsets(&inset); |
| 198 DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(), | 187 DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(), |
| 199 inset); | 188 inset); |
| 200 | 189 |
| 190 PaintChildBorder(canvas); | |
| 191 | |
| 201 // Draw the bottom line. | 192 // Draw the bottom line. |
| 202 int y = owner_->height() + 1; | 193 int y = owner_->height() + 1; |
| 203 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(), | 194 canvas->FillRect(gfx::Rect(inset.left(), y, owner_->width(), |
| 204 kBottomLineHeight), kBorderDarkColor); | 195 kBottomLineHeight), kBorderDarkColor); |
| 205 | 196 |
| 206 if (!Shell::GetInstance()->shelf()->IsVisible()) | 197 if (!Shell::GetInstance()->shelf()->IsVisible() || |
| 198 arrow_location() == views::BubbleBorder::NONE) | |
| 207 return; | 199 return; |
| 208 | 200 |
| 209 // Draw the arrow. | 201 // Draw the arrow after drawing child borders, so that the arrow can cover |
| 210 if (arrow_type_ == ARROW_TYPE_BOTTOM) { | 202 // the its overlap section with child border. |
| 203 SkPath path; | |
| 204 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) { | |
| 211 int tip_x = base::i18n::IsRTL() ? arrow_offset_ : | 205 int tip_x = base::i18n::IsRTL() ? arrow_offset_ : |
| 212 owner_->width() - arrow_offset_; | 206 owner_->width() - arrow_offset_; |
| 213 int left_base_x = tip_x - kArrowWidth / 2; | 207 int left_base_x = tip_x - kArrowWidth / 2; |
| 214 int left_base_y = y; | 208 int left_base_y = y; |
| 215 int tip_y = left_base_y + kArrowHeight; | 209 int tip_y = left_base_y + kArrowHeight; |
| 216 | |
| 217 SkPath path; | |
| 218 path.incReserve(4); | 210 path.incReserve(4); |
|
sadrul
2012/05/17 23:30:29
Move this line after line 203 and remove from othe
jennyz
2012/05/18 00:00:42
Done.
| |
| 219 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); | 211 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); |
| 220 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 212 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
| 221 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), | 213 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), |
| 222 SkIntToScalar(left_base_y)); | 214 SkIntToScalar(left_base_y)); |
| 215 } else if (arrow_location() == views::BubbleBorder::LEFT_BOTTOM) { | |
| 216 int tip_y = y - arrow_offset_; | |
| 217 int top_base_y = tip_y - kArrowWidth / 2; | |
| 218 int top_base_x = inset.left() + kSystemTrayBubbleHorizontalInset; | |
| 219 int tip_x = top_base_x - kArrowHeight; | |
| 220 path.incReserve(4); | |
| 221 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); | |
| 222 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | |
| 223 path.lineTo(SkIntToScalar(top_base_x), | |
| 224 SkIntToScalar(top_base_y + kArrowWidth)); | |
| 225 } else if (arrow_location() == views::BubbleBorder::RIGHT_BOTTOM){ | |
| 226 int tip_y = y - arrow_offset_; | |
|
sadrul
2012/05/17 23:30:29
spacing in this block seems off
jennyz
2012/05/18 00:00:42
Done.
| |
| 227 int top_base_y = tip_y - kArrowWidth / 2; | |
| 228 int top_base_x = inset.left() + owner_->width() - | |
| 229 kSystemTrayBubbleHorizontalInset; | |
| 230 int tip_x = top_base_x + kArrowHeight; | |
| 231 path.incReserve(4); | |
| 232 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); | |
| 233 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | |
| 234 path.lineTo(SkIntToScalar(top_base_x), | |
| 235 SkIntToScalar(top_base_y + kArrowWidth)); | |
| 236 } | |
| 223 | 237 |
| 224 SkPaint paint; | 238 SkPaint paint; |
| 225 paint.setStyle(SkPaint::kFill_Style); | 239 paint.setStyle(SkPaint::kFill_Style); |
| 226 paint.setColor(kHeaderBackgroundColorDark); | 240 paint.setColor(kHeaderBackgroundColorDark); |
| 227 canvas->DrawPath(path, paint); | 241 canvas->DrawPath(path, paint); |
| 228 | 242 |
| 229 // Now draw the arrow border. | 243 // Now draw the arrow border. |
| 230 paint.setStyle(SkPaint::kStroke_Style); | 244 paint.setStyle(SkPaint::kStroke_Style); |
| 231 paint.setColor(kBorderDarkColor); | 245 paint.setColor(kBorderDarkColor); |
| 232 canvas->DrawPath(path, paint); | 246 canvas->DrawPath(path, paint); |
| 233 } | 247 |
| 234 } | 248 } |
| 235 | 249 |
| 236 views::View* owner_; | 250 views::View* owner_; |
| 237 ArrowType arrow_type_; | |
| 238 const int arrow_offset_; | 251 const int arrow_offset_; |
| 239 | 252 |
| 240 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); | 253 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); |
| 241 }; | 254 }; |
| 242 | 255 |
| 243 } // namespace | 256 } // namespace |
| 244 | 257 |
| 245 namespace internal { | 258 namespace internal { |
| 246 | 259 |
| 247 // SystemTrayBubbleView | 260 // SystemTrayBubbleView |
| 248 | 261 |
| 249 SystemTrayBubbleView::SystemTrayBubbleView(views::View* anchor, | 262 SystemTrayBubbleView::SystemTrayBubbleView(views::View* anchor, |
| 250 SystemTrayBubble* host, | 263 views::BubbleBorder::ArrowLocation arrow_location, |
| 251 bool can_activate) | 264 SystemTrayBubble* host, |
| 252 : views::BubbleDelegateView(anchor, views::BubbleBorder::BOTTOM_RIGHT), | 265 bool can_activate) |
| 266 : views::BubbleDelegateView(anchor, arrow_location), | |
| 253 host_(host), | 267 host_(host), |
| 254 can_activate_(can_activate) { | 268 can_activate_(can_activate) { |
| 255 set_margin(0); | 269 set_margin(0); |
| 256 set_parent_window(ash::Shell::GetInstance()->GetContainer( | 270 set_parent_window(ash::Shell::GetInstance()->GetContainer( |
| 257 ash::internal::kShellWindowId_SettingBubbleContainer)); | 271 ash::internal::kShellWindowId_SettingBubbleContainer)); |
| 258 set_notify_enter_exit_on_child(true); | 272 set_notify_enter_exit_on_child(true); |
| 259 } | 273 } |
| 260 | 274 |
| 261 SystemTrayBubbleView::~SystemTrayBubbleView() { | 275 SystemTrayBubbleView::~SystemTrayBubbleView() { |
| 262 // Inform host items (models) that their views are being destroyed. | 276 // Inform host items (models) that their views are being destroyed. |
| 263 if (host_) | 277 if (host_) |
| 264 host_->DestroyItemViews(); | 278 host_->DestroyItemViews(); |
| 265 } | 279 } |
| 266 | 280 |
| 267 void SystemTrayBubbleView::SetBubbleBorder(views::BubbleBorder* border) { | 281 void SystemTrayBubbleView::SetBubbleBorder(views::BubbleBorder* border) { |
| 268 GetBubbleFrameView()->SetBubbleBorder(border); | 282 GetBubbleFrameView()->SetBubbleBorder(border); |
| 269 } | 283 } |
| 270 | 284 |
| 271 void SystemTrayBubbleView::UpdateAnchor() { | 285 void SystemTrayBubbleView::UpdateAnchor() { |
| 272 SizeToContents(); | 286 SizeToContents(); |
| 273 GetWidget()->GetRootView()->SchedulePaint(); | 287 GetWidget()->GetRootView()->SchedulePaint(); |
| 274 } | 288 } |
| 275 | 289 |
| 276 void SystemTrayBubbleView::Init() { | 290 void SystemTrayBubbleView::Init() { |
| 277 views::BoxLayout* layout = | 291 views::BoxLayout* layout = |
| 278 new views::BoxLayout(views::BoxLayout::kVertical, 1, 1, 1); | 292 new views::BoxLayout(views::BoxLayout::kVertical, |
| 293 kSystemTrayBubbleHorizontalInset, | |
| 294 kSystemTrayBubbleVerticalInset, | |
| 295 1); | |
| 279 layout->set_spread_blank_space(true); | 296 layout->set_spread_blank_space(true); |
| 280 SetLayoutManager(layout); | 297 SetLayoutManager(layout); |
| 281 set_background(new SystemTrayBubbleBackground(this)); | 298 set_background(NULL); |
| 282 } | 299 } |
| 283 | 300 |
| 284 gfx::Rect SystemTrayBubbleView::GetAnchorRect() { | 301 gfx::Rect SystemTrayBubbleView::GetAnchorRect() { |
| 285 gfx::Rect rect; | 302 gfx::Rect rect; |
| 286 if (host_) | 303 if (host_) |
| 287 rect = host_->GetAnchorRect(); | 304 rect = host_->GetAnchorRect(); |
| 305 // TODO(jennyz): May need to add left/right alignment in the following code. | |
| 288 if (rect.IsEmpty()) { | 306 if (rect.IsEmpty()) { |
| 289 rect = gfx::Screen::GetPrimaryMonitor().bounds(); | 307 rect = gfx::Screen::GetPrimaryMonitor().bounds(); |
| 290 rect = gfx::Rect(base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreen : | 308 rect = gfx::Rect( |
| 291 rect.width() - kPaddingFromRightEdgeOfScreen, | 309 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : |
| 292 rect.height() - kPaddingFromBottomOfScreen, | 310 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
| 293 0, 0); | 311 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
| 312 0, 0); | |
| 294 } | 313 } |
| 295 return rect; | 314 return rect; |
| 296 } | 315 } |
| 297 | 316 |
| 298 void SystemTrayBubbleView::ChildPreferredSizeChanged(View* child) { | 317 void SystemTrayBubbleView::ChildPreferredSizeChanged(View* child) { |
| 299 SizeToContents(); | 318 SizeToContents(); |
| 300 } | 319 } |
| 301 | 320 |
| 302 void SystemTrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { | 321 void SystemTrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 303 if (can_activate_) { | 322 if (can_activate_) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 | 390 |
| 372 items_ = items; | 391 items_ = items; |
| 373 bubble_type_ = bubble_type; | 392 bubble_type_ = bubble_type; |
| 374 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); | 393 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); |
| 375 bubble_widget_->GetContentsView()->Layout(); | 394 bubble_widget_->GetContentsView()->Layout(); |
| 376 } | 395 } |
| 377 | 396 |
| 378 void SystemTrayBubble::InitView(const InitParams& init_params) { | 397 void SystemTrayBubble::InitView(const InitParams& init_params) { |
| 379 DCHECK(bubble_view_ == NULL); | 398 DCHECK(bubble_view_ == NULL); |
| 380 anchor_type_ = init_params.anchor_type; | 399 anchor_type_ = init_params.anchor_type; |
| 400 views::BubbleBorder::ArrowLocation arrow_location; | |
| 401 if (anchor_type_ == ANCHOR_TYPE_TRAY) { | |
| 402 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | |
| 403 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; | |
| 404 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | |
| 405 arrow_location = views::BubbleBorder::LEFT_BOTTOM; | |
| 406 } else { | |
| 407 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; | |
| 408 } | |
| 409 } else { | |
| 410 arrow_location = views::BubbleBorder::NONE; | |
| 411 } | |
| 381 bubble_view_ = new SystemTrayBubbleView( | 412 bubble_view_ = new SystemTrayBubbleView( |
| 382 init_params.anchor, this, init_params.can_activate); | 413 init_params.anchor, arrow_location, this, init_params.can_activate); |
| 383 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) | 414 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) |
| 384 bubble_view_->set_close_on_deactivate(false); | 415 bubble_view_->set_close_on_deactivate(false); |
| 385 | 416 |
| 386 CreateItemViews(init_params.login_status); | 417 CreateItemViews(init_params.login_status); |
| 387 | 418 |
| 388 DCHECK(bubble_widget_ == NULL); | 419 DCHECK(bubble_widget_ == NULL); |
| 389 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | 420 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
| 390 | 421 |
| 391 // Must occur after call to CreateBubble() | 422 // Must occur after call to CreateBubble() |
| 392 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 423 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 393 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | 424 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
| 394 SystemTrayBubbleBorder::ArrowType arrow_type; | |
| 395 if (anchor_type_ == ANCHOR_TYPE_TRAY) | |
| 396 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM; | |
| 397 else | |
| 398 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_NONE; | |
| 399 | |
| 400 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( | 425 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( |
| 401 bubble_view_, arrow_type, init_params.arrow_offset); | 426 bubble_view_, arrow_location, init_params.arrow_offset); |
| 402 bubble_view_->SetBubbleBorder(bubble_border); | 427 bubble_view_->SetBubbleBorder(bubble_border); |
| 403 | 428 |
| 404 bubble_widget_->AddObserver(this); | 429 bubble_widget_->AddObserver(this); |
| 405 | 430 |
| 406 // Setup animation. | 431 // Setup animation. |
| 407 ash::SetWindowVisibilityAnimationType( | 432 ash::SetWindowVisibilityAnimationType( |
| 408 bubble_widget_->GetNativeWindow(), | 433 bubble_widget_->GetNativeWindow(), |
| 409 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 434 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 410 ash::SetWindowVisibilityAnimationTransition( | 435 ash::SetWindowVisibilityAnimationTransition( |
| 411 bubble_widget_->GetNativeWindow(), | 436 bubble_widget_->GetNativeWindow(), |
| 412 ash::ANIMATE_BOTH); | 437 ash::ANIMATE_BOTH); |
| 413 ash::SetWindowVisibilityAnimationDuration( | 438 ash::SetWindowVisibilityAnimationDuration( |
| 414 bubble_widget_->GetNativeWindow(), | 439 bubble_widget_->GetNativeWindow(), |
| 415 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | 440 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); |
| 416 | 441 |
| 417 bubble_view_->Show(); | 442 bubble_view_->Show(); |
| 418 } | 443 } |
| 419 | 444 |
| 420 gfx::Rect SystemTrayBubble::GetAnchorRect() const { | 445 gfx::Rect SystemTrayBubble::GetAnchorRect() const { |
| 421 gfx::Rect rect; | 446 gfx::Rect rect; |
| 422 views::Widget* widget = bubble_view()->anchor_widget(); | 447 views::Widget* widget = bubble_view()->anchor_widget(); |
| 423 if (widget->IsVisible()) { | 448 if (widget->IsVisible()) { |
| 424 rect = widget->GetWindowScreenBounds(); | 449 rect = widget->GetWindowScreenBounds(); |
| 425 if (anchor_type_ == ANCHOR_TYPE_TRAY) { | 450 if (anchor_type_ == ANCHOR_TYPE_TRAY) { |
| 426 rect.Inset( | 451 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 427 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreen : 0, | 452 rect.Inset( |
| 428 0, | 453 base::i18n::IsRTL() ? |
| 429 base::i18n::IsRTL() ? 0 : kPaddingFromRightEdgeOfScreen, | 454 kPaddingFromRightEdgeOfScreenBottomAlignment : 0, |
| 430 kPaddingFromBottomOfScreen); | 455 0, |
| 456 base::i18n::IsRTL() ? | |
| 457 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 458 kPaddingFromBottomOfScreenBottomAlignment); | |
| 459 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | |
| 460 rect.Inset(0, 0, kPaddingFromLeftEdgeOfScreenLeftAlignment, | |
| 461 kPaddingFromBottomOfScreenVerticalAlignment); | |
| 462 } else { | |
| 463 rect.Inset(-kPaddingFromRightEdgeOfScreenRightAlignment, | |
| 464 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | |
| 465 } | |
| 431 } else if (anchor_type_ == ANCHOR_TYPE_BUBBLE) { | 466 } else if (anchor_type_ == ANCHOR_TYPE_BUBBLE) { |
| 467 // TODO(jennyz): add left/right launcher support for notification bubble. | |
| 432 rect.Inset( | 468 rect.Inset( |
| 433 base::i18n::IsRTL() ? kShadowThickness - 1 : 0, | 469 base::i18n::IsRTL() ? kShadowThickness - 1 : 0, |
| 434 0, | 470 0, |
| 435 base::i18n::IsRTL() ? 0 : kShadowThickness - 1, | 471 base::i18n::IsRTL() ? 0 : kShadowThickness - 1, |
| 436 0); | 472 0); |
| 437 } | 473 } |
| 438 } | 474 } |
| 439 return rect; | 475 return rect; |
| 440 } | 476 } |
| 441 | 477 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 } | 539 } |
| 504 | 540 |
| 505 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { | 541 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { |
| 506 CHECK_EQ(bubble_widget_, widget); | 542 CHECK_EQ(bubble_widget_, widget); |
| 507 bubble_widget_ = NULL; | 543 bubble_widget_ = NULL; |
| 508 tray_->RemoveBubble(this); | 544 tray_->RemoveBubble(this); |
| 509 } | 545 } |
| 510 | 546 |
| 511 } // namespace internal | 547 } // namespace internal |
| 512 } // namespace ash | 548 } // namespace ash |
| OLD | NEW |