| 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/frame/custom_frame_view_ash.h" | 5 #include "ash/frame/custom_frame_view_ash.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
| 25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_observer.h" | 26 #include "ui/aura/window_observer.h" |
| 27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 29 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 30 #include "ui/gfx/rect_conversions.h" | 30 #include "ui/gfx/rect_conversions.h" |
| 31 #include "ui/gfx/size.h" | 31 #include "ui/gfx/size.h" |
| 32 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
| 33 #include "ui/views/view.h" | 33 #include "ui/views/view.h" |
| 34 #include "ui/views/view_targeter.h" |
| 34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 35 #include "ui/views/widget/widget_delegate.h" | 36 #include "ui/views/widget/widget_delegate.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
| 40 // CustomFrameViewAshWindowStateDelegate | 41 // CustomFrameViewAshWindowStateDelegate |
| 41 | 42 |
| 42 // Handles a user's fullscreen request (Shift+F4/F4). Puts the window into | 43 // Handles a user's fullscreen request (Shift+F4/F4). Puts the window into |
| 43 // immersive fullscreen if immersive fullscreen is enabled for non-browser | 44 // immersive fullscreen if immersive fullscreen is enabled for non-browser |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 gfx::Rect(visible_origin_in_screen, visible_bounds.size())); | 343 gfx::Rect(visible_origin_in_screen, visible_bounds.size())); |
| 343 return bounds_in_screen; | 344 return bounds_in_screen; |
| 344 } | 345 } |
| 345 | 346 |
| 346 /////////////////////////////////////////////////////////////////////////////// | 347 /////////////////////////////////////////////////////////////////////////////// |
| 347 // CustomFrameViewAsh::OverlayView | 348 // CustomFrameViewAsh::OverlayView |
| 348 | 349 |
| 349 // View which takes up the entire widget and contains the HeaderView. HeaderView | 350 // View which takes up the entire widget and contains the HeaderView. HeaderView |
| 350 // is a child of OverlayView to avoid creating a larger texture than necessary | 351 // is a child of OverlayView to avoid creating a larger texture than necessary |
| 351 // when painting the HeaderView to its own layer. | 352 // when painting the HeaderView to its own layer. |
| 352 class CustomFrameViewAsh::OverlayView : public views::View { | 353 class CustomFrameViewAsh::OverlayView : public views::View, |
| 354 public views::ViewTargeterDelegate { |
| 353 public: | 355 public: |
| 354 explicit OverlayView(HeaderView* header_view); | 356 explicit OverlayView(HeaderView* header_view); |
| 355 virtual ~OverlayView(); | 357 virtual ~OverlayView(); |
| 356 | 358 |
| 357 // views::View override: | 359 // views::View: |
| 358 virtual void Layout() OVERRIDE; | 360 virtual void Layout() OVERRIDE; |
| 359 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; | 361 |
| 362 // views::ViewTargeterDelegate: |
| 363 virtual bool DoesIntersectRect(const views::View* target, |
| 364 const gfx::Rect& rect) const OVERRIDE; |
| 360 | 365 |
| 361 private: | 366 private: |
| 362 HeaderView* header_view_; | 367 HeaderView* header_view_; |
| 363 | 368 |
| 364 DISALLOW_COPY_AND_ASSIGN(OverlayView); | 369 DISALLOW_COPY_AND_ASSIGN(OverlayView); |
| 365 }; | 370 }; |
| 366 | 371 |
| 367 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) | 372 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) |
| 368 : header_view_(header_view) { | 373 : header_view_(header_view) { |
| 369 AddChildView(header_view); | 374 AddChildView(header_view); |
| 375 SetEventTargeter( |
| 376 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 370 } | 377 } |
| 371 | 378 |
| 372 CustomFrameViewAsh::OverlayView::~OverlayView() { | 379 CustomFrameViewAsh::OverlayView::~OverlayView() { |
| 373 } | 380 } |
| 374 | 381 |
| 375 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
| 376 // CustomFrameViewAsh::OverlayView, views::View overrides: | 383 // CustomFrameViewAsh::OverlayView, views::View overrides: |
| 377 | 384 |
| 378 void CustomFrameViewAsh::OverlayView::Layout() { | 385 void CustomFrameViewAsh::OverlayView::Layout() { |
| 379 // Layout |header_view_| because layout affects the result of | 386 // Layout |header_view_| because layout affects the result of |
| 380 // GetPreferredOnScreenHeight(). | 387 // GetPreferredOnScreenHeight(). |
| 381 header_view_->Layout(); | 388 header_view_->Layout(); |
| 382 | 389 |
| 383 int onscreen_height = header_view_->GetPreferredOnScreenHeight(); | 390 int onscreen_height = header_view_->GetPreferredOnScreenHeight(); |
| 384 if (onscreen_height == 0) { | 391 if (onscreen_height == 0) { |
| 385 header_view_->SetVisible(false); | 392 header_view_->SetVisible(false); |
| 386 } else { | 393 } else { |
| 387 int height = header_view_->GetPreferredHeight(); | 394 int height = header_view_->GetPreferredHeight(); |
| 388 header_view_->SetBounds(0, onscreen_height - height, width(), height); | 395 header_view_->SetBounds(0, onscreen_height - height, width(), height); |
| 389 header_view_->SetVisible(true); | 396 header_view_->SetVisible(true); |
| 390 } | 397 } |
| 391 } | 398 } |
| 392 | 399 |
| 393 bool CustomFrameViewAsh::OverlayView::HitTestRect(const gfx::Rect& rect) const { | 400 /////////////////////////////////////////////////////////////////////////////// |
| 401 // CustomFrameViewAsh::OverlayView, views::ViewTargeterDelegate overrides: |
| 402 |
| 403 bool CustomFrameViewAsh::OverlayView::DoesIntersectRect( |
| 404 const views::View* target, |
| 405 const gfx::Rect& rect) const { |
| 406 CHECK_EQ(target, this); |
| 394 // Grab events in the header view. Return false for other events so that they | 407 // Grab events in the header view. Return false for other events so that they |
| 395 // can be handled by the client view. | 408 // can be handled by the client view. |
| 396 return header_view_->HitTestRect(rect); | 409 return header_view_->HitTestRect(rect); |
| 397 } | 410 } |
| 398 | 411 |
| 399 //////////////////////////////////////////////////////////////////////////////// | 412 //////////////////////////////////////////////////////////////////////////////// |
| 400 // CustomFrameViewAsh, public: | 413 // CustomFrameViewAsh, public: |
| 401 | 414 |
| 402 // static | 415 // static |
| 403 const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh"; | 416 const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh"; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // The HeaderView is not a child of CustomFrameViewAsh. Redirect the paint | 519 // The HeaderView is not a child of CustomFrameViewAsh. Redirect the paint |
| 507 // to HeaderView instead. | 520 // to HeaderView instead. |
| 508 gfx::RectF to_paint(r); | 521 gfx::RectF to_paint(r); |
| 509 views::View::ConvertRectToTarget(this, header_view_, &to_paint); | 522 views::View::ConvertRectToTarget(this, header_view_, &to_paint); |
| 510 header_view_->SchedulePaintInRect(gfx::ToEnclosingRect(to_paint)); | 523 header_view_->SchedulePaintInRect(gfx::ToEnclosingRect(to_paint)); |
| 511 } else { | 524 } else { |
| 512 views::NonClientFrameView::SchedulePaintInRect(r); | 525 views::NonClientFrameView::SchedulePaintInRect(r); |
| 513 } | 526 } |
| 514 } | 527 } |
| 515 | 528 |
| 516 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { | |
| 517 // NonClientView hit tests the NonClientFrameView first instead of going in | |
| 518 // z-order. Return false so that events get to the OverlayView. | |
| 519 return false; | |
| 520 } | |
| 521 | |
| 522 void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from, | 529 void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from, |
| 523 bool is_visible) { | 530 bool is_visible) { |
| 524 if (is_visible) | 531 if (is_visible) |
| 525 header_view_->UpdateAvatarIcon(); | 532 header_view_->UpdateAvatarIcon(); |
| 526 } | 533 } |
| 527 | 534 |
| 535 //////////////////////////////////////////////////////////////////////////////// |
| 536 // CustomFrameViewAsh, views::ViewTargeterDelegate overrides: |
| 537 |
| 538 bool CustomFrameViewAsh::DoesIntersectRect(const views::View* target, |
| 539 const gfx::Rect& rect) const { |
| 540 CHECK_EQ(target, this); |
| 541 // NonClientView hit tests the NonClientFrameView first instead of going in |
| 542 // z-order. Return false so that events get to the OverlayView. |
| 543 return false; |
| 544 } |
| 545 |
| 528 views::View* CustomFrameViewAsh::GetHeaderView() { | 546 views::View* CustomFrameViewAsh::GetHeaderView() { |
| 529 return header_view_; | 547 return header_view_; |
| 530 } | 548 } |
| 531 | 549 |
| 532 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const { | 550 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const { |
| 533 return header_view_->avatar_icon(); | 551 return header_view_->avatar_icon(); |
| 534 } | 552 } |
| 535 | 553 |
| 536 //////////////////////////////////////////////////////////////////////////////// | 554 //////////////////////////////////////////////////////////////////////////////// |
| 537 // CustomFrameViewAsh, private: | 555 // CustomFrameViewAsh, private: |
| 538 | 556 |
| 539 FrameCaptionButtonContainerView* CustomFrameViewAsh:: | 557 FrameCaptionButtonContainerView* CustomFrameViewAsh:: |
| 540 GetFrameCaptionButtonContainerViewForTest() { | 558 GetFrameCaptionButtonContainerViewForTest() { |
| 541 return header_view_->caption_button_container(); | 559 return header_view_->caption_button_container(); |
| 542 } | 560 } |
| 543 | 561 |
| 544 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 562 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
| 545 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 563 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
| 546 } | 564 } |
| 547 | 565 |
| 548 } // namespace ash | 566 } // namespace ash |
| OLD | NEW |