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