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 "ui/views/bubble/tray_bubble_view.h" | 5 #include "ui/views/bubble/tray_bubble_view.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
8 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
9 #include "third_party/skia/include/core/SkPaint.h" | 11 #include "third_party/skia/include/core/SkPaint.h" |
10 #include "third_party/skia/include/core/SkPath.h" | 12 #include "third_party/skia/include/core/SkPath.h" |
11 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
12 #include "ui/base/accessibility/accessible_view_state.h" | 14 #include "ui/base/accessibility/accessible_view_state.h" |
13 #include "ui/base/events/event.h" | 15 #include "ui/base/events/event.h" |
14 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
16 #include "ui/compositor/layer_delegate.h" | 18 #include "ui/compositor/layer_delegate.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 214 |
213 using internal::TrayBubbleBorder; | 215 using internal::TrayBubbleBorder; |
214 using internal::TrayBubbleContentMask; | 216 using internal::TrayBubbleContentMask; |
215 using internal::BottomAlignedBoxLayout; | 217 using internal::BottomAlignedBoxLayout; |
216 | 218 |
217 // static | 219 // static |
218 const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1; | 220 const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1; |
219 | 221 |
220 TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, | 222 TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, |
221 AnchorAlignment anchor_alignment, | 223 AnchorAlignment anchor_alignment, |
222 int bubble_width) | 224 int min_width, |
| 225 int max_width) |
223 : anchor_type(anchor_type), | 226 : anchor_type(anchor_type), |
224 anchor_alignment(anchor_alignment), | 227 anchor_alignment(anchor_alignment), |
225 bubble_width(bubble_width), | 228 min_width(min_width), |
| 229 max_width(max_width), |
226 max_height(0), | 230 max_height(0), |
227 can_activate(false), | 231 can_activate(false), |
228 close_on_deactivate(true), | 232 close_on_deactivate(true), |
229 arrow_color(SK_ColorBLACK), | 233 arrow_color(SK_ColorBLACK), |
230 arrow_location(views::BubbleBorder::NONE), | 234 arrow_location(views::BubbleBorder::NONE), |
231 arrow_offset(kArrowDefaultOffset), | 235 arrow_offset(kArrowDefaultOffset), |
232 shadow(views::BubbleBorder::BIG_SHADOW) { | 236 shadow(views::BubbleBorder::BIG_SHADOW) { |
233 } | 237 } |
234 | 238 |
235 // static | 239 // static |
(...skipping 19 matching lines...) Expand all Loading... |
255 return new TrayBubbleView(parent_window, anchor, delegate, *init_params); | 259 return new TrayBubbleView(parent_window, anchor, delegate, *init_params); |
256 } | 260 } |
257 | 261 |
258 TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window, | 262 TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window, |
259 views::View* anchor, | 263 views::View* anchor, |
260 Delegate* delegate, | 264 Delegate* delegate, |
261 const InitParams& init_params) | 265 const InitParams& init_params) |
262 : views::BubbleDelegateView(anchor, init_params.arrow_location), | 266 : views::BubbleDelegateView(anchor, init_params.arrow_location), |
263 params_(init_params), | 267 params_(init_params), |
264 delegate_(delegate), | 268 delegate_(delegate), |
| 269 preferred_width_(init_params.min_width), |
265 bubble_border_(NULL), | 270 bubble_border_(NULL), |
266 is_gesture_dragging_(false) { | 271 is_gesture_dragging_(false) { |
267 set_parent_window(parent_window); | 272 set_parent_window(parent_window); |
268 set_notify_enter_exit_on_child(true); | 273 set_notify_enter_exit_on_child(true); |
269 set_close_on_deactivate(init_params.close_on_deactivate); | 274 set_close_on_deactivate(init_params.close_on_deactivate); |
270 set_margins(gfx::Insets()); | 275 set_margins(gfx::Insets()); |
271 SetPaintToLayer(true); | 276 SetPaintToLayer(true); |
272 SetFillsBoundsOpaquely(true); | 277 SetFillsBoundsOpaquely(true); |
273 | 278 |
274 bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_); | 279 bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_); |
(...skipping 24 matching lines...) Expand all Loading... |
299 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); | 304 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); |
300 GetWidget()->GetRootView()->SchedulePaint(); | 305 GetWidget()->GetRootView()->SchedulePaint(); |
301 } | 306 } |
302 | 307 |
303 void TrayBubbleView::SetMaxHeight(int height) { | 308 void TrayBubbleView::SetMaxHeight(int height) { |
304 params_.max_height = height; | 309 params_.max_height = height; |
305 if (GetWidget()) | 310 if (GetWidget()) |
306 SizeToContents(); | 311 SizeToContents(); |
307 } | 312 } |
308 | 313 |
| 314 void TrayBubbleView::SetWidth(int width) { |
| 315 width = std::max(std::min(width, params_.max_width), params_.min_width); |
| 316 if (preferred_width_ == width) |
| 317 return; |
| 318 preferred_width_ = width; |
| 319 if (GetWidget()) |
| 320 SizeToContents(); |
| 321 } |
| 322 |
309 void TrayBubbleView::SetPaintArrow(bool paint_arrow) { | 323 void TrayBubbleView::SetPaintArrow(bool paint_arrow) { |
310 bubble_border_->set_paint_arrow(paint_arrow); | 324 bubble_border_->set_paint_arrow(paint_arrow); |
311 } | 325 } |
312 | 326 |
313 gfx::Insets TrayBubbleView::GetBorderInsets() const { | 327 gfx::Insets TrayBubbleView::GetBorderInsets() const { |
314 return bubble_border_->GetInsets(); | 328 return bubble_border_->GetInsets(); |
315 } | 329 } |
316 | 330 |
317 void TrayBubbleView::Init() { | 331 void TrayBubbleView::Init() { |
318 views::BoxLayout* layout = new BottomAlignedBoxLayout(this); | 332 views::BoxLayout* layout = new BottomAlignedBoxLayout(this); |
(...skipping 28 matching lines...) Expand all Loading... |
347 void TrayBubbleView::GetWidgetHitTestMask(gfx::Path* mask) const { | 361 void TrayBubbleView::GetWidgetHitTestMask(gfx::Path* mask) const { |
348 DCHECK(mask); | 362 DCHECK(mask); |
349 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); | 363 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); |
350 } | 364 } |
351 | 365 |
352 gfx::Size TrayBubbleView::GetPreferredSize() { | 366 gfx::Size TrayBubbleView::GetPreferredSize() { |
353 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); | 367 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); |
354 int height = size.height(); | 368 int height = size.height(); |
355 if (params_.max_height != 0 && height > params_.max_height) | 369 if (params_.max_height != 0 && height > params_.max_height) |
356 height = params_.max_height; | 370 height = params_.max_height; |
357 return gfx::Size(params_.bubble_width, height); | 371 return gfx::Size(preferred_width_, height); |
| 372 } |
| 373 |
| 374 gfx::Size TrayBubbleView::GetMaximumSize() { |
| 375 gfx::Size size = GetPreferredSize(); |
| 376 size.set_width(params_.max_width); |
| 377 return size; |
358 } | 378 } |
359 | 379 |
360 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { | 380 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
361 if (delegate_) | 381 if (delegate_) |
362 delegate_->OnMouseEnteredView(); | 382 delegate_->OnMouseEnteredView(); |
363 } | 383 } |
364 | 384 |
365 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { | 385 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
366 if (delegate_) | 386 if (delegate_) |
367 delegate_->OnMouseExitedView(); | 387 delegate_->OnMouseExitedView(); |
(...skipping 14 matching lines...) Expand all Loading... |
382 views::View* parent, | 402 views::View* parent, |
383 views::View* child) { | 403 views::View* child) { |
384 if (is_add && child == this) { | 404 if (is_add && child == this) { |
385 parent->SetPaintToLayer(true); | 405 parent->SetPaintToLayer(true); |
386 parent->SetFillsBoundsOpaquely(true); | 406 parent->SetFillsBoundsOpaquely(true); |
387 parent->layer()->SetMasksToBounds(true); | 407 parent->layer()->SetMasksToBounds(true); |
388 } | 408 } |
389 } | 409 } |
390 | 410 |
391 } // namespace views | 411 } // namespace views |
OLD | NEW |