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