| 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/wm/panel_frame_view.h" |
| 6 |
| 5 #include "ash/wm/frame_painter.h" | 7 #include "ash/wm/frame_painter.h" |
| 6 #include "ash/wm/panel_frame_view.h" | |
| 7 #include "grit/ash_resources.h" | 8 #include "grit/ash_resources.h" |
| 8 #include "grit/ui_strings.h" // Accessibility names | 9 #include "grit/ui_strings.h" // Accessibility names |
| 9 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
| 10 #include "ui/base/animation/throb_animation.h" | 11 #include "ui/base/animation/throb_animation.h" |
| 11 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 12 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
| 17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 18 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
| 19 #include "ui/views/widget/native_widget_aura.h" | 20 #include "ui/views/widget/native_widget_aura.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 | 25 |
| 25 PanelFrameView::PanelFrameView(views::Widget* frame) | 26 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) { |
| 26 : frame_painter_(new FramePainter) { | 27 if (frame_type != FRAME_NONE) |
| 28 InitFramePainter(frame); |
| 29 } |
| 30 |
| 31 PanelFrameView::~PanelFrameView() { |
| 32 } |
| 33 |
| 34 void PanelFrameView::InitFramePainter(views::Widget* frame) { |
| 35 frame_painter_.reset(new FramePainter); |
| 36 |
| 27 close_button_ = new views::ImageButton(this); | 37 close_button_ = new views::ImageButton(this); |
| 28 close_button_->SetAccessibleName( | 38 close_button_->SetAccessibleName( |
| 29 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 39 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
| 30 AddChildView(close_button_); | 40 AddChildView(close_button_); |
| 31 | 41 |
| 32 minimize_button_ = new views::ImageButton(this); | 42 minimize_button_ = new views::ImageButton(this); |
| 33 minimize_button_->SetAccessibleName( | 43 minimize_button_->SetAccessibleName( |
| 34 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 44 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
| 35 AddChildView(minimize_button_); | 45 AddChildView(minimize_button_); |
| 36 | 46 |
| 37 frame_painter_->Init(frame, NULL, minimize_button_, close_button_, | 47 frame_painter_->Init(frame, NULL, minimize_button_, close_button_, |
| 38 FramePainter::SIZE_BUTTON_MINIMIZES); | 48 FramePainter::SIZE_BUTTON_MINIMIZES); |
| 39 } | 49 } |
| 40 | 50 |
| 41 PanelFrameView::~PanelFrameView() { | |
| 42 } | |
| 43 | |
| 44 void PanelFrameView::Layout() { | 51 void PanelFrameView::Layout() { |
| 52 if (!frame_painter_.get()) |
| 53 return; |
| 45 frame_painter_->LayoutHeader(this, true); | 54 frame_painter_->LayoutHeader(this, true); |
| 46 } | 55 } |
| 47 | 56 |
| 48 void PanelFrameView::ResetWindowControls() { | 57 void PanelFrameView::ResetWindowControls() { |
| 49 NOTIMPLEMENTED(); | 58 NOTIMPLEMENTED(); |
| 50 } | 59 } |
| 51 | 60 |
| 52 void PanelFrameView::UpdateWindowIcon() { | 61 void PanelFrameView::UpdateWindowIcon() { |
| 53 NOTIMPLEMENTED(); | 62 NOTIMPLEMENTED(); |
| 54 } | 63 } |
| 55 | 64 |
| 56 void PanelFrameView::UpdateWindowTitle() { | 65 void PanelFrameView::UpdateWindowTitle() { |
| 57 NOTIMPLEMENTED(); | 66 // TODO(stevenjb): Support titles for panels? |
| 58 } | 67 } |
| 59 | 68 |
| 60 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { | 69 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { |
| 61 // Nothing. | 70 // Nothing. |
| 62 } | 71 } |
| 63 | 72 |
| 64 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { | 73 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { |
| 74 if (!frame_painter_.get()) |
| 75 return HTNOWHERE; |
| 65 return frame_painter_->NonClientHitTest(this, point); | 76 return frame_painter_->NonClientHitTest(this, point); |
| 66 } | 77 } |
| 67 | 78 |
| 68 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { | 79 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { |
| 80 if (!frame_painter_.get()) |
| 81 return; |
| 69 bool paint_as_active = ShouldPaintAsActive(); | 82 bool paint_as_active = ShouldPaintAsActive(); |
| 70 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE : | 83 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE : |
| 71 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; | 84 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; |
| 72 frame_painter_->PaintHeader( | 85 frame_painter_->PaintHeader( |
| 73 this, | 86 this, |
| 74 canvas, | 87 canvas, |
| 75 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE, | 88 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE, |
| 76 theme_image_id, | 89 theme_image_id, |
| 77 NULL); | 90 NULL); |
| 78 frame_painter_->PaintHeaderContentSeparator(this, canvas); | 91 frame_painter_->PaintHeaderContentSeparator(this, canvas); |
| 79 } | 92 } |
| 80 | 93 |
| 81 gfx::Rect PanelFrameView::GetBoundsForClientView() const { | 94 gfx::Rect PanelFrameView::GetBoundsForClientView() const { |
| 95 if (!frame_painter_.get()) |
| 96 return bounds(); |
| 82 return frame_painter_->GetBoundsForClientView( | 97 return frame_painter_->GetBoundsForClientView( |
| 83 close_button_->bounds().bottom(), | 98 close_button_->bounds().bottom(), |
| 84 bounds()); | 99 bounds()); |
| 85 } | 100 } |
| 86 | 101 |
| 87 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( | 102 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( |
| 88 const gfx::Rect& client_bounds) const { | 103 const gfx::Rect& client_bounds) const { |
| 104 if (!frame_painter_.get()) |
| 105 return client_bounds; |
| 89 return frame_painter_->GetWindowBoundsForClientBounds( | 106 return frame_painter_->GetWindowBoundsForClientBounds( |
| 90 close_button_->bounds().bottom(), client_bounds); | 107 close_button_->bounds().bottom(), client_bounds); |
| 91 } | 108 } |
| 92 | 109 |
| 93 void PanelFrameView::ButtonPressed(views::Button* sender, | 110 void PanelFrameView::ButtonPressed(views::Button* sender, |
| 94 const ui::Event& event) { | 111 const ui::Event& event) { |
| 95 if (sender == close_button_) | 112 if (sender == close_button_) |
| 96 GetWidget()->Close(); | 113 GetWidget()->Close(); |
| 114 if (sender == minimize_button_) |
| 115 GetWidget()->Minimize(); |
| 97 } | 116 } |
| 98 | 117 |
| 99 } // namespace ash | 118 } // namespace ash |
| OLD | NEW |