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/tray_bubble_view.h" | 5 #include "ash/system/tray/tray_bubble_view.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/shell_window_ids.h" | |
| 10 #include "ash/system/tray/tray_constants.h" | |
| 11 #include "ash/wm/property_util.h" | |
| 12 #include "ash/wm/shelf_layout_manager.h" | |
| 13 #include "ash/wm/window_animations.h" | |
| 14 #include "grit/ash_strings.h" | |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 7 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "third_party/skia/include/core/SkPaint.h" | 9 #include "third_party/skia/include/core/SkPaint.h" |
| 18 #include "third_party/skia/include/core/SkPath.h" | 10 #include "third_party/skia/include/core/SkPath.h" |
| 19 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 11 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 20 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 21 #include "ui/base/accessibility/accessible_view_state.h" | 13 #include "ui/base/accessibility/accessible_view_state.h" |
| 22 #include "ui/base/events/event.h" | 14 #include "ui/base/events/event.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/insets.h" | 17 #include "ui/gfx/insets.h" |
| 26 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
| 27 #include "ui/gfx/screen.h" | |
| 28 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 29 #include "ui/views/bubble/bubble_frame_view.h" | 20 #include "ui/views/bubble/bubble_frame_view.h" |
| 30 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
| 31 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 32 | 23 |
| 33 namespace ash { | 24 namespace { |
| 34 | |
| 35 namespace internal { | |
| 36 | 25 |
| 37 // Inset the arrow a bit from the edge. | 26 // Inset the arrow a bit from the edge. |
| 38 const int kArrowMinOffset = 20; | 27 const int kArrowMinOffset = 20; |
| 39 const int kBubbleSpacing = 20; | 28 const int kBubbleSpacing = 20; |
| 40 | 29 |
| 41 const int kAnimationDurationForPopupMS = 200; | 30 } // namespace |
| 31 | |
| 32 namespace ash { | |
| 42 | 33 |
| 43 // Custom border for TrayBubbleView. Contains special logic for GetBounds() | 34 // Custom border for TrayBubbleView. Contains special logic for GetBounds() |
| 44 // to stack bubbles with no arrows correctly. Also calculates the arrow offset. | 35 // to stack bubbles with no arrows correctly. Also calculates the arrow offset. |
| 45 class TrayBubbleBorder : public views::BubbleBorder { | 36 class TrayBubbleBorder : public views::BubbleBorder { |
| 46 public: | 37 public: |
| 47 TrayBubbleBorder(views::View* owner, | 38 TrayBubbleBorder(views::View* owner, |
| 48 views::View* anchor, | 39 views::View* anchor, |
| 49 views::BubbleBorder::ArrowLocation arrow_location, | |
| 50 TrayBubbleView::InitParams params) | 40 TrayBubbleView::InitParams params) |
| 51 : views::BubbleBorder(arrow_location, params.shadow), | 41 : views::BubbleBorder(params.arrow_location, params.shadow), |
| 52 owner_(owner), | 42 owner_(owner), |
| 53 anchor_(anchor), | 43 anchor_(anchor), |
| 54 tray_arrow_offset_(params.arrow_offset) { | 44 tray_arrow_offset_(params.arrow_offset) { |
| 55 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 45 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 56 set_background_color(params.arrow_color); | 46 set_background_color(params.arrow_color); |
| 57 } | 47 } |
| 58 | 48 |
| 59 virtual ~TrayBubbleBorder() {} | 49 virtual ~TrayBubbleBorder() {} |
| 60 | 50 |
| 61 // Overridden from views::BubbleBorder. | 51 // Overridden from views::BubbleBorder. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 80 + insets.height() - kBubbleSpacing; | 70 + insets.height() - kBubbleSpacing; |
| 81 return gfx::Rect(x, y, border_size.width(), border_size.height()); | 71 return gfx::Rect(x, y, border_size.width(), border_size.height()); |
| 82 } | 72 } |
| 83 | 73 |
| 84 void UpdateArrowOffset() { | 74 void UpdateArrowOffset() { |
| 85 int arrow_offset = 0; | 75 int arrow_offset = 0; |
| 86 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT || | 76 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT || |
| 87 arrow_location() == views::BubbleBorder::BOTTOM_LEFT) { | 77 arrow_location() == views::BubbleBorder::BOTTOM_LEFT) { |
| 88 // Note: tray_arrow_offset_ is relative to the anchor widget. | 78 // Note: tray_arrow_offset_ is relative to the anchor widget. |
| 89 if (tray_arrow_offset_ == | 79 if (tray_arrow_offset_ == |
| 90 internal::TrayBubbleView::InitParams::kArrowDefaultOffset) { | 80 TrayBubbleView::InitParams::kArrowDefaultOffset) { |
| 91 arrow_offset = kArrowMinOffset; | 81 arrow_offset = kArrowMinOffset; |
| 92 } else { | 82 } else { |
| 93 const int width = owner_->GetWidget()->GetContentsView()->width(); | 83 const int width = owner_->GetWidget()->GetContentsView()->width(); |
| 94 gfx::Point pt(tray_arrow_offset_, 0); | 84 gfx::Point pt(tray_arrow_offset_, 0); |
| 95 views::View::ConvertPointToScreen( | 85 views::View::ConvertPointToScreen( |
| 96 anchor_->GetWidget()->GetRootView(), &pt); | 86 anchor_->GetWidget()->GetRootView(), &pt); |
| 97 views::View::ConvertPointFromScreen( | 87 views::View::ConvertPointFromScreen( |
| 98 owner_->GetWidget()->GetRootView(), &pt); | 88 owner_->GetWidget()->GetRootView(), &pt); |
| 99 arrow_offset = pt.x(); | 89 arrow_offset = pt.x(); |
| 100 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) | 90 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) |
| 101 arrow_offset = width - arrow_offset; | 91 arrow_offset = width - arrow_offset; |
| 102 arrow_offset = std::max(arrow_offset, kArrowMinOffset); | 92 arrow_offset = std::max(arrow_offset, kArrowMinOffset); |
| 103 } | 93 } |
| 104 } else { | 94 } else { |
| 105 if (tray_arrow_offset_ == | 95 if (tray_arrow_offset_ == |
| 106 internal::TrayBubbleView::InitParams::kArrowDefaultOffset) { | 96 TrayBubbleView::InitParams::kArrowDefaultOffset) { |
| 107 arrow_offset = kArrowMinOffset; | 97 arrow_offset = kArrowMinOffset; |
| 108 } else { | 98 } else { |
| 109 gfx::Point pt(0, tray_arrow_offset_); | 99 gfx::Point pt(0, tray_arrow_offset_); |
| 110 views::View::ConvertPointToScreen( | 100 views::View::ConvertPointToScreen( |
| 111 anchor_->GetWidget()->GetRootView(), &pt); | 101 anchor_->GetWidget()->GetRootView(), &pt); |
| 112 views::View::ConvertPointFromScreen( | 102 views::View::ConvertPointFromScreen( |
| 113 owner_->GetWidget()->GetRootView(), &pt); | 103 owner_->GetWidget()->GetRootView(), &pt); |
| 114 arrow_offset = pt.y(); | 104 arrow_offset = pt.y(); |
| 115 arrow_offset = std::max(arrow_offset, kArrowMinOffset); | 105 arrow_offset = std::max(arrow_offset, kArrowMinOffset); |
| 116 } | 106 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 SkColor bottom_color_; | 168 SkColor bottom_color_; |
| 179 SkScalar radius_; | 169 SkScalar radius_; |
| 180 | 170 |
| 181 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBackground); | 171 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBackground); |
| 182 }; | 172 }; |
| 183 | 173 |
| 184 // Custom layout for the bubble-view. Does the default box-layout if there is | 174 // Custom layout for the bubble-view. Does the default box-layout if there is |
| 185 // enough height. Otherwise, makes sure the bottom rows are visible. | 175 // enough height. Otherwise, makes sure the bottom rows are visible. |
| 186 class BottomAlignedBoxLayout : public views::BoxLayout { | 176 class BottomAlignedBoxLayout : public views::BoxLayout { |
| 187 public: | 177 public: |
| 188 explicit BottomAlignedBoxLayout(internal::TrayBubbleView* bubble_view) | 178 explicit BottomAlignedBoxLayout(TrayBubbleView* bubble_view) |
| 189 : views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0), | 179 : views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0), |
| 190 bubble_view_(bubble_view) { | 180 bubble_view_(bubble_view) { |
| 191 } | 181 } |
| 192 | 182 |
| 193 virtual ~BottomAlignedBoxLayout() {} | 183 virtual ~BottomAlignedBoxLayout() {} |
| 194 | 184 |
| 195 private: | 185 private: |
| 196 virtual void Layout(views::View* host) OVERRIDE { | 186 virtual void Layout(views::View* host) OVERRIDE { |
| 197 if (host->height() >= host->GetPreferredSize().height() || | 187 if (host->height() >= host->GetPreferredSize().height() || |
| 198 !bubble_view_->is_gesture_dragging()) { | 188 !bubble_view_->is_gesture_dragging()) { |
| 199 views::BoxLayout::Layout(host); | 189 views::BoxLayout::Layout(host); |
| 200 return; | 190 return; |
| 201 } | 191 } |
| 202 | 192 |
| 203 int consumed_height = 0; | 193 int consumed_height = 0; |
| 204 for (int i = host->child_count() - 1; | 194 for (int i = host->child_count() - 1; |
| 205 i >= 0 && consumed_height < host->height(); --i) { | 195 i >= 0 && consumed_height < host->height(); --i) { |
| 206 views::View* child = host->child_at(i); | 196 views::View* child = host->child_at(i); |
| 207 if (!child->visible()) | 197 if (!child->visible()) |
| 208 continue; | 198 continue; |
| 209 gfx::Size size = child->GetPreferredSize(); | 199 gfx::Size size = child->GetPreferredSize(); |
| 210 child->SetBounds(0, host->height() - consumed_height - size.height(), | 200 child->SetBounds(0, host->height() - consumed_height - size.height(), |
| 211 host->width(), size.height()); | 201 host->width(), size.height()); |
| 212 consumed_height += size.height(); | 202 consumed_height += size.height(); |
| 213 } | 203 } |
| 214 } | 204 } |
| 215 | 205 |
| 216 internal::TrayBubbleView* bubble_view_; | 206 TrayBubbleView* bubble_view_; |
| 217 | 207 |
| 218 DISALLOW_COPY_AND_ASSIGN(BottomAlignedBoxLayout); | 208 DISALLOW_COPY_AND_ASSIGN(BottomAlignedBoxLayout); |
| 219 }; | 209 }; |
| 220 | 210 |
| 221 // static | 211 // static |
| 222 const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1; | 212 const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1; |
| 223 | 213 |
| 224 TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, | 214 TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, |
| 225 ShelfAlignment shelf_alignment) | 215 AnchorAlignment anchor_alignment, |
| 216 int bubble_width) | |
| 226 : anchor_type(anchor_type), | 217 : anchor_type(anchor_type), |
| 227 shelf_alignment(shelf_alignment), | 218 anchor_alignment(anchor_alignment), |
| 228 bubble_width(kTrayPopupWidth), | 219 bubble_width(bubble_width), |
| 229 max_height(0), | 220 max_height(0), |
| 230 can_activate(false), | 221 can_activate(false), |
| 231 close_on_deactivate(true), | 222 close_on_deactivate(true), |
| 232 top_color(SK_ColorBLACK), | 223 top_color(SK_ColorBLACK), |
| 233 arrow_color(SK_ColorBLACK), | 224 arrow_color(SK_ColorBLACK), |
| 225 arrow_location(views::BubbleBorder::NONE), | |
| 234 arrow_offset(kArrowDefaultOffset), | 226 arrow_offset(kArrowDefaultOffset), |
| 235 shadow(views::BubbleBorder::BIG_SHADOW) { | 227 shadow(views::BubbleBorder::BIG_SHADOW) { |
| 236 } | 228 } |
| 237 | 229 |
| 238 TrayBubbleView* TrayBubbleView::Create(views::View* anchor, | 230 TrayBubbleView* TrayBubbleView::Create(aura::Window* parent_window, |
| 239 Host* host, | 231 views::View* anchor, |
| 240 const InitParams& init_params) { | 232 Delegate* delegate, |
| 233 InitParams* init_params) { | |
| 241 // Set arrow_location here so that it can be passed correctly to the | 234 // Set arrow_location here so that it can be passed correctly to the |
| 242 // BubbleView constructor. | 235 // BubbleView constructor. |
| 243 views::BubbleBorder::ArrowLocation arrow_location; | 236 if (init_params->anchor_type == ANCHOR_TYPE_TRAY) { |
| 244 if (init_params.anchor_type == ANCHOR_TYPE_TRAY) { | 237 if (init_params->anchor_alignment == ANCHOR_ALIGNMENT_BOTTOM) { |
| 245 if (init_params.shelf_alignment == SHELF_ALIGNMENT_BOTTOM) { | 238 init_params->arrow_location = base::i18n::IsRTL() ? |
| 246 arrow_location = base::i18n::IsRTL() ? | |
| 247 views::BubbleBorder::BOTTOM_LEFT : views::BubbleBorder::BOTTOM_RIGHT; | 239 views::BubbleBorder::BOTTOM_LEFT : views::BubbleBorder::BOTTOM_RIGHT; |
| 248 } else if (init_params.shelf_alignment == SHELF_ALIGNMENT_LEFT) { | 240 } else if (init_params->anchor_alignment == ANCHOR_ALIGNMENT_LEFT) { |
| 249 arrow_location = views::BubbleBorder::LEFT_BOTTOM; | 241 init_params->arrow_location = views::BubbleBorder::LEFT_BOTTOM; |
| 250 } else { | 242 } else { |
| 251 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; | 243 init_params->arrow_location = views::BubbleBorder::RIGHT_BOTTOM; |
| 252 } | 244 } |
| 253 } else { | 245 } else { |
| 254 arrow_location = views::BubbleBorder::NONE; | 246 init_params->arrow_location = views::BubbleBorder::NONE; |
| 255 } | 247 } |
| 256 | 248 |
| 257 return new TrayBubbleView(init_params, arrow_location, anchor, host); | 249 return new TrayBubbleView(parent_window, anchor, delegate, *init_params); |
| 258 } | 250 } |
| 259 | 251 |
| 260 TrayBubbleView::TrayBubbleView( | 252 TrayBubbleView::TrayBubbleView(aura::Window* parent_window, |
| 261 const InitParams& init_params, | 253 views::View* anchor, |
| 262 views::BubbleBorder::ArrowLocation arrow_location, | 254 Delegate* delegate, |
| 263 views::View* anchor, | 255 const InitParams& init_params) |
| 264 Host* host) | 256 : views::BubbleDelegateView(anchor, init_params.arrow_location), |
| 265 : views::BubbleDelegateView(anchor, arrow_location), | |
| 266 params_(init_params), | 257 params_(init_params), |
| 267 host_(host), | 258 delegate_(delegate), |
| 268 bubble_border_(NULL), | 259 bubble_border_(NULL), |
| 269 bubble_background_(NULL), | 260 bubble_background_(NULL), |
| 270 is_gesture_dragging_(false) { | 261 is_gesture_dragging_(false) { |
| 271 set_parent_window(Shell::GetContainer( | 262 set_parent_window(parent_window); |
| 272 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), | |
| 273 internal::kShellWindowId_SettingBubbleContainer)); | |
| 274 set_notify_enter_exit_on_child(true); | 263 set_notify_enter_exit_on_child(true); |
| 275 set_close_on_deactivate(init_params.close_on_deactivate); | 264 set_close_on_deactivate(init_params.close_on_deactivate); |
| 276 SetPaintToLayer(true); | 265 SetPaintToLayer(true); |
| 277 SetFillsBoundsOpaquely(true); | 266 SetFillsBoundsOpaquely(true); |
| 278 | 267 |
| 279 bubble_border_ = new TrayBubbleBorder( | 268 bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_); |
| 280 this, anchor_view(), arrow_location, params_); | |
| 281 | 269 |
| 282 bubble_background_ = new TrayBubbleBackground( | 270 bubble_background_ = new TrayBubbleBackground( |
| 283 bubble_border_, init_params.top_color, init_params.arrow_color); | 271 bubble_border_, init_params.top_color, init_params.arrow_color); |
| 284 | 272 |
| 285 // Inset the view on the top and bottom by the corner radius to avoid drawing | 273 // Inset the view on the top and bottom by the corner radius to avoid drawing |
| 286 // over the the bubble corners. | 274 // over the the bubble corners. |
| 287 const int radius = bubble_background_->radius(); | 275 const int radius = bubble_background_->radius(); |
| 288 set_margins(gfx::Insets(radius, 0, radius, 0)); | 276 set_margins(gfx::Insets(radius, 0, radius, 0)); |
| 289 } | 277 } |
| 290 | 278 |
| 291 TrayBubbleView::~TrayBubbleView() { | 279 TrayBubbleView::~TrayBubbleView() { |
| 292 // Inform host items (models) that their views are being destroyed. | 280 // Inform host items (models) that their views are being destroyed. |
| 293 if (host_) | 281 if (delegate_) |
| 294 host_->BubbleViewDestroyed(); | 282 delegate_->BubbleViewDestroyed(); |
| 283 } | |
| 284 | |
| 285 void TrayBubbleView::InitializeAndShowBubble(views::Widget* widget) { | |
|
jennyz
2012/10/12 23:05:34
The input argument widget is not used, remove it?
stevenjb
2012/10/12 23:41:50
Done.
| |
| 286 // Must occur after call to BubbleDelegateView::CreateBubble(). | |
| 287 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
| 288 bubble_border_->UpdateArrowOffset(); | |
| 289 | |
| 290 Show(); | |
| 291 UpdateBubble(); | |
| 295 } | 292 } |
| 296 | 293 |
| 297 void TrayBubbleView::UpdateBubble() { | 294 void TrayBubbleView::UpdateBubble() { |
| 298 SizeToContents(); | 295 SizeToContents(); |
| 299 GetWidget()->GetRootView()->SchedulePaint(); | 296 GetWidget()->GetRootView()->SchedulePaint(); |
| 300 } | 297 } |
| 301 | 298 |
| 302 void TrayBubbleView::SetMaxHeight(int height) { | 299 void TrayBubbleView::SetMaxHeight(int height) { |
| 303 params_.max_height = height; | 300 params_.max_height = height; |
| 304 if (GetWidget()) | 301 if (GetWidget()) |
| 305 SizeToContents(); | 302 SizeToContents(); |
| 306 } | 303 } |
| 307 | 304 |
| 305 void TrayBubbleView::GetBorderInsets(gfx::Insets* insets) const { | |
| 306 bubble_border_->GetInsets(insets); | |
| 307 } | |
| 308 | |
| 308 void TrayBubbleView::Init() { | 309 void TrayBubbleView::Init() { |
| 309 views::BoxLayout* layout = new BottomAlignedBoxLayout(this); | 310 views::BoxLayout* layout = new BottomAlignedBoxLayout(this); |
| 310 layout->set_spread_blank_space(true); | 311 layout->set_spread_blank_space(true); |
| 311 SetLayoutManager(layout); | 312 SetLayoutManager(layout); |
| 312 } | 313 } |
| 313 | 314 |
| 314 gfx::Rect TrayBubbleView::GetAnchorRect() { | 315 gfx::Rect TrayBubbleView::GetAnchorRect() { |
| 315 gfx::Rect rect; | 316 if (!delegate_) |
| 316 | 317 return gfx::Rect(); |
| 317 if (anchor_widget() && anchor_widget()->IsVisible()) { | 318 return delegate_->GetAnchorRect(anchor_widget(), |
| 318 rect = anchor_widget()->GetWindowBoundsInScreen(); | 319 params_.anchor_type, |
| 319 if (params_.anchor_type == ANCHOR_TYPE_TRAY) { | 320 params_.anchor_alignment); |
| 320 if (params_.shelf_alignment == SHELF_ALIGNMENT_BOTTOM) { | |
| 321 bool rtl = base::i18n::IsRTL(); | |
| 322 rect.Inset( | |
| 323 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, | |
| 324 0, | |
| 325 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 326 kPaddingFromBottomOfScreenBottomAlignment); | |
| 327 } else if (params_.shelf_alignment == SHELF_ALIGNMENT_LEFT) { | |
| 328 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
| 329 kPaddingFromBottomOfScreenVerticalAlignment); | |
| 330 } else { | |
| 331 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
| 332 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | |
| 333 } | |
| 334 } else if (params_.anchor_type == ANCHOR_TYPE_BUBBLE) { | |
| 335 // Invert the offsets to align with the bubble below. | |
| 336 if (params_.shelf_alignment == SHELF_ALIGNMENT_LEFT) { | |
| 337 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
| 338 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | |
| 339 } else if (params_.shelf_alignment == SHELF_ALIGNMENT_RIGHT) { | |
| 340 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
| 341 kPaddingFromBottomOfScreenVerticalAlignment); | |
| 342 } | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 // TODO(jennyz): May need to add left/right alignment in the following code. | |
| 347 if (rect.IsEmpty()) { | |
| 348 rect = gfx::Screen::GetPrimaryDisplay().bounds(); | |
| 349 rect = gfx::Rect( | |
| 350 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : | |
| 351 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | |
| 352 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | |
| 353 0, 0); | |
| 354 } | |
| 355 return rect; | |
| 356 } | 321 } |
| 357 | 322 |
| 358 bool TrayBubbleView::CanActivate() const { | 323 bool TrayBubbleView::CanActivate() const { |
| 359 return params_.can_activate; | 324 return params_.can_activate; |
| 360 } | 325 } |
| 361 | 326 |
| 362 // Overridden to create BubbleFrameView and set a custom border and background. | 327 // Overridden to create BubbleFrameView and set a custom border and background. |
| 363 views::NonClientFrameView* TrayBubbleView::CreateNonClientFrameView( | 328 views::NonClientFrameView* TrayBubbleView::CreateNonClientFrameView( |
| 364 views::Widget* widget) { | 329 views::Widget* widget) { |
| 365 views::BubbleFrameView* bubble_frame_view = | 330 views::BubbleFrameView* bubble_frame_view = |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 379 | 344 |
| 380 gfx::Size TrayBubbleView::GetPreferredSize() { | 345 gfx::Size TrayBubbleView::GetPreferredSize() { |
| 381 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); | 346 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); |
| 382 int height = size.height(); | 347 int height = size.height(); |
| 383 if (params_.max_height != 0 && height > params_.max_height) | 348 if (params_.max_height != 0 && height > params_.max_height) |
| 384 height = params_.max_height; | 349 height = params_.max_height; |
| 385 return gfx::Size(params_.bubble_width, height); | 350 return gfx::Size(params_.bubble_width, height); |
| 386 } | 351 } |
| 387 | 352 |
| 388 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { | 353 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
| 389 if (host_) | 354 if (delegate_) |
| 390 host_->OnMouseEnteredView(); | 355 delegate_->OnMouseEnteredView(); |
| 391 } | 356 } |
| 392 | 357 |
| 393 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { | 358 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
| 394 if (host_) | 359 if (delegate_) |
| 395 host_->OnMouseExitedView(); | 360 delegate_->OnMouseExitedView(); |
| 396 } | 361 } |
| 397 | 362 |
| 398 void TrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { | 363 void TrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 399 if (params_.can_activate) { | 364 if (params_.can_activate) { |
| 400 state->role = ui::AccessibilityTypes::ROLE_WINDOW; | 365 state->role = ui::AccessibilityTypes::ROLE_WINDOW; |
| 401 state->name = host_->GetAccessibleName(); | 366 state->name = delegate_->GetAccessibleName(); |
| 402 } | 367 } |
| 403 } | 368 } |
| 404 | 369 |
| 405 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { | 370 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { |
| 406 SizeToContents(); | 371 SizeToContents(); |
| 407 } | 372 } |
| 408 | 373 |
| 409 void TrayBubbleView::ViewHierarchyChanged(bool is_add, | 374 void TrayBubbleView::ViewHierarchyChanged(bool is_add, |
| 410 views::View* parent, | 375 views::View* parent, |
| 411 views::View* child) { | 376 views::View* child) { |
| 412 if (is_add && child == this) { | 377 if (is_add && child == this) { |
| 413 parent->SetPaintToLayer(true); | 378 parent->SetPaintToLayer(true); |
| 414 parent->SetFillsBoundsOpaquely(true); | 379 parent->SetFillsBoundsOpaquely(true); |
| 415 parent->layer()->SetMasksToBounds(true); | 380 parent->layer()->SetMasksToBounds(true); |
| 416 } | 381 } |
| 417 } | 382 } |
| 418 | 383 |
| 419 TrayBubbleView::Host::Host() | |
| 420 : widget_(NULL), | |
| 421 bubble_view_(NULL), | |
| 422 tray_view_(NULL) { | |
| 423 Shell::GetInstance()->AddEnvEventFilter(this); | |
| 424 } | |
| 425 | |
| 426 TrayBubbleView::Host::~Host() { | |
| 427 Shell::GetInstance()->RemoveEnvEventFilter(this); | |
| 428 } | |
| 429 | |
| 430 void TrayBubbleView::Host::InitializeAndShowBubble(views::Widget* widget, | |
| 431 TrayBubbleView* bubble_view, | |
| 432 views::View* tray_view) { | |
| 433 widget_ = widget; | |
| 434 bubble_view_ = bubble_view; | |
| 435 tray_view_ = tray_view; | |
| 436 | |
| 437 // Must occur after call to BubbleDelegateView::CreateBubble(). | |
| 438 bubble_view->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
| 439 | |
| 440 bubble_view->bubble_border()->UpdateArrowOffset(); | |
| 441 | |
| 442 // Setup animation. | |
| 443 ash::SetWindowVisibilityAnimationType( | |
| 444 widget->GetNativeWindow(), | |
| 445 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
| 446 ash::SetWindowVisibilityAnimationTransition( | |
| 447 widget->GetNativeWindow(), | |
| 448 ash::ANIMATE_BOTH); | |
| 449 ash::SetWindowVisibilityAnimationDuration( | |
| 450 widget->GetNativeWindow(), | |
| 451 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | |
| 452 | |
| 453 bubble_view->Show(); | |
| 454 bubble_view->UpdateBubble(); | |
| 455 } | |
| 456 | |
| 457 bool TrayBubbleView::Host::PreHandleKeyEvent(aura::Window* target, | |
| 458 ui::KeyEvent* event) { | |
| 459 return false; | |
| 460 } | |
| 461 | |
| 462 bool TrayBubbleView::Host::PreHandleMouseEvent(aura::Window* target, | |
| 463 ui::MouseEvent* event) { | |
| 464 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 465 ProcessLocatedEvent(target, *event); | |
| 466 return false; | |
| 467 } | |
| 468 | |
| 469 ui::TouchStatus TrayBubbleView::Host::PreHandleTouchEvent( | |
| 470 aura::Window* target, | |
| 471 ui::TouchEvent* event) { | |
| 472 if (event->type() == ui::ET_TOUCH_PRESSED) | |
| 473 ProcessLocatedEvent(target, *event); | |
| 474 return ui::TOUCH_STATUS_UNKNOWN; | |
| 475 } | |
| 476 | |
| 477 ui::EventResult TrayBubbleView::Host::PreHandleGestureEvent( | |
| 478 aura::Window* target, | |
| 479 ui::GestureEvent* event) { | |
| 480 return ui::ER_UNHANDLED; | |
| 481 } | |
| 482 | |
| 483 void TrayBubbleView::Host::ProcessLocatedEvent( | |
| 484 aura::Window* target, const ui::LocatedEvent& event) { | |
| 485 if (target) { | |
| 486 // Don't process events that occurred inside an embedded menu. | |
| 487 RootWindowController* root_controller = | |
| 488 GetRootWindowController(target->GetRootWindow()); | |
| 489 if (root_controller && root_controller->GetContainer( | |
| 490 ash::internal::kShellWindowId_MenuContainer)->Contains(target)) { | |
| 491 return; | |
| 492 } | |
| 493 } | |
| 494 if (!widget_) | |
| 495 return; | |
| 496 gfx::Rect bounds = widget_->GetWindowBoundsInScreen(); | |
| 497 gfx::Insets insets; | |
| 498 bubble_view_->bubble_border()->GetInsets(&insets); | |
| 499 bounds.Inset(insets); | |
| 500 if (bounds.Contains(event.root_location())) | |
| 501 return; | |
| 502 if (tray_view_) { | |
| 503 // If the user clicks on the parent tray, don't process the event here, | |
| 504 // let the tray logic handle the event and determine show/hide behavior. | |
| 505 bounds = tray_view_->GetWidget()->GetClientAreaBoundsInScreen(); | |
| 506 if (bounds.Contains(event.root_location())) | |
| 507 return; | |
| 508 } | |
| 509 // Handle clicking outside the bubble and tray. We don't block the event, so | |
| 510 // it will also be handled by whatever widget was clicked on. | |
| 511 OnClickedOutsideView(); | |
| 512 } | |
| 513 | |
| 514 | |
| 515 } // namespace internal | |
| 516 } // namespace ash | 384 } // namespace ash |
| OLD | NEW |