Home | History | Annotate | Download | only in panels
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ash/wm/panels/panel_frame_view.h"
      6 
      7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
      8 #include "ash/frame/default_header_painter.h"
      9 #include "ash/frame/frame_border_hit_test_controller.h"
     10 #include "ui/base/hit_test.h"
     11 #include "ui/gfx/canvas.h"
     12 #include "ui/views/controls/image_view.h"
     13 #include "ui/views/widget/widget.h"
     14 #include "ui/views/widget/widget_delegate.h"
     15 
     16 namespace ash {
     17 
     18 // static
     19 const char PanelFrameView::kViewClassName[] = "PanelFrameView";
     20 
     21 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type)
     22     : frame_(frame),
     23       caption_button_container_(NULL),
     24       window_icon_(NULL),
     25       frame_border_hit_test_controller_(
     26           new FrameBorderHitTestController(frame_)) {
     27   DCHECK(!frame_->widget_delegate()->CanMaximize());
     28   if (frame_type != FRAME_NONE)
     29     InitHeaderPainter();
     30 }
     31 
     32 PanelFrameView::~PanelFrameView() {
     33 }
     34 
     35 const char* PanelFrameView::GetClassName() const {
     36   return kViewClassName;
     37 }
     38 
     39 void PanelFrameView::InitHeaderPainter() {
     40   header_painter_.reset(new DefaultHeaderPainter);
     41 
     42   caption_button_container_ = new FrameCaptionButtonContainerView(frame_,
     43       FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
     44   AddChildView(caption_button_container_);
     45 
     46   header_painter_->Init(frame_, this, caption_button_container_);
     47 
     48   if (frame_->widget_delegate()->ShouldShowWindowIcon()) {
     49     window_icon_ = new views::ImageView();
     50     AddChildView(window_icon_);
     51     header_painter_->UpdateLeftHeaderView(window_icon_);
     52   }
     53 }
     54 
     55 int PanelFrameView::NonClientTopBorderHeight() const {
     56   if (!header_painter_)
     57     return 0;
     58   return header_painter_->GetHeaderHeightForPainting();
     59 }
     60 
     61 gfx::Size PanelFrameView::GetMinimumSize() const {
     62   if (!header_painter_)
     63     return gfx::Size();
     64   gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize());
     65   return gfx::Size(
     66       std::max(header_painter_->GetMinimumHeaderWidth(),
     67                min_client_view_size.width()),
     68       NonClientTopBorderHeight() + min_client_view_size.height());
     69 }
     70 
     71 void PanelFrameView::Layout() {
     72   if (!header_painter_)
     73     return;
     74   header_painter_->LayoutHeader();
     75 }
     76 
     77 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) {
     78   // Nothing.
     79 }
     80 
     81 void PanelFrameView::ResetWindowControls() {
     82   NOTIMPLEMENTED();
     83 }
     84 
     85 void PanelFrameView::UpdateWindowIcon() {
     86   if (!window_icon_)
     87     return;
     88   views::WidgetDelegate* delegate = frame_->widget_delegate();
     89   if (delegate)
     90     window_icon_->SetImage(delegate->GetWindowIcon());
     91   window_icon_->SchedulePaint();
     92 }
     93 
     94 void PanelFrameView::UpdateWindowTitle() {
     95   if (!header_painter_)
     96     return;
     97   header_painter_->SchedulePaintForTitle();
     98 }
     99 
    100 void PanelFrameView::SizeConstraintsChanged() {
    101 }
    102 
    103 int PanelFrameView::NonClientHitTest(const gfx::Point& point) {
    104   if (!header_painter_)
    105     return HTNOWHERE;
    106   return FrameBorderHitTestController::NonClientHitTest(this,
    107       caption_button_container_, point);
    108 }
    109 
    110 void PanelFrameView::OnPaint(gfx::Canvas* canvas) {
    111   if (!header_painter_)
    112     return;
    113   bool paint_as_active = ShouldPaintAsActive();
    114   caption_button_container_->SetPaintAsActive(paint_as_active);
    115 
    116   HeaderPainter::Mode header_mode = paint_as_active ?
    117       HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE;
    118   header_painter_->PaintHeader(canvas, header_mode);
    119 }
    120 
    121 gfx::Rect PanelFrameView::GetBoundsForClientView() const {
    122   gfx::Rect client_bounds = bounds();
    123   client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0);
    124   return client_bounds;
    125 }
    126 
    127 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds(
    128     const gfx::Rect& client_bounds) const {
    129   gfx::Rect window_bounds = client_bounds;
    130   window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0);
    131   return window_bounds;
    132 }
    133 
    134 }  // namespace ash
    135