Index: ash/wm/dialog_frame_view.cc |
=================================================================== |
--- ash/wm/dialog_frame_view.cc (revision 0) |
+++ ash/wm/dialog_frame_view.cc (revision 0) |
@@ -0,0 +1,133 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/wm/dialog_frame_view.h" |
+ |
+#include "ui/gfx/canvas.h" |
+#include "ui/gfx/font.h" |
+#include "ui/views/background.h" |
+#include "ui/views/border.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/widget/widget_delegate.h" |
+ |
+namespace ash { |
+namespace internal { |
+ |
+// static |
+const char DialogFrameView::kViewClassName[] = "ash/wm/DialogFrameView"; |
+ |
+// static |
+gfx::Font* DialogFrameView::title_font_ = NULL; |
+ |
+// TODO(benrg): tweak these values until they match kennedy-spec. |
+// TODO(benrg): this may also mean tweaking the frame shadow opacity. |
+const SkColor kDialogBackgroundColor = SK_ColorWHITE; |
+const SkColor kDialogBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); |
+const SkColor kDialogTitleColor = SK_ColorBLACK; |
+ |
+// TODO(benrg): Replace with width-based padding heuristic. |
+static int kDialogPadding = 30; |
+static int kDialogContentVSpacing = 18; |
+ |
+const int kCloseButtonSize = 16; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// DialogFrameView, public: |
+ |
+DialogFrameView::DialogFrameView() { |
+ set_background(views::Background::CreateSolidBackground( |
+ kDialogBackgroundColor)); |
+ set_border(views::Border::CreateSolidBorder(1, kDialogBorderColor)); |
+ if (!title_font_) |
+ title_font_ = new gfx::Font(gfx::Font().DeriveFont(4, gfx::Font::NORMAL)); |
+} |
+ |
+DialogFrameView::~DialogFrameView() { |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// DialogFrameView, views::NonClientFrameView: |
+ |
+gfx::Rect DialogFrameView::GetBoundsForClientView() const { |
+ gfx::Rect client_bounds = GetLocalBounds(); |
+ client_bounds.Inset(kDialogPadding, GetNonClientTopHeight(), |
+ kDialogPadding, kDialogPadding); |
+ return client_bounds; |
+} |
+ |
+gfx::Rect DialogFrameView::GetWindowBoundsForClientBounds( |
+ const gfx::Rect& client_bounds) const { |
+ gfx::Rect window_bounds = client_bounds; |
+ window_bounds.Inset(-kDialogPadding, -GetNonClientTopHeight(), |
+ -kDialogPadding, -kDialogPadding); |
+ return window_bounds; |
+} |
+ |
+int DialogFrameView::NonClientHitTest(const gfx::Point& point) { |
+ if (close_button_rect_.Contains(point)) |
+ return HTCLOSE; |
+ return point.y() < GetNonClientTopHeight() ? HTCAPTION : HTCLIENT; |
+} |
+ |
+void DialogFrameView::GetWindowMask(const gfx::Size& size, |
+ gfx::Path* window_mask) { |
+ // Nothing to do. |
+} |
+ |
+void DialogFrameView::ResetWindowControls() { |
+ // Nothing to do. |
+} |
+ |
+void DialogFrameView::UpdateWindowIcon() { |
+ // Nothing to do. |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// DialogFrameView, views::View overrides: |
+ |
+std::string DialogFrameView::GetClassName() const { |
+ return kViewClassName; |
+} |
+ |
+void DialogFrameView::Layout() { |
+ title_display_rect_ = GetLocalBounds(); |
+ // TODO(benrg): size based on font height rather than bottom padding. |
+ close_button_rect_.SetRect(width() - kDialogPadding - kCloseButtonSize, |
+ kDialogPadding, kCloseButtonSize, |
+ kCloseButtonSize); |
+ title_display_rect_.Inset(kDialogPadding, kDialogPadding, |
+ kDialogPadding + kCloseButtonSize, kDialogPadding); |
+ title_display_rect_.set_height(title_font_->GetHeight()); |
+} |
+ |
+void DialogFrameView::OnPaint(gfx::Canvas* canvas) { |
+ views::View::OnPaint(canvas); |
+ canvas->FillRect(SK_ColorRED, close_button_rect_); |
+ views::WidgetDelegate* delegate = GetWidget()->widget_delegate(); |
+ if (!delegate) |
+ return; |
+ canvas->DrawStringInt(delegate->GetWindowTitle(), *title_font_, |
+ kDialogTitleColor, title_display_rect_); |
+} |
+ |
+// TODO(benrg): You may want to use a views::Button for the close box instead. |
+bool DialogFrameView::OnMousePressed(const views::MouseEvent& event) { |
+ if (close_button_rect_.Contains(event.location())) |
+ return true; |
+ return View::OnMousePressed(event); |
+} |
+void DialogFrameView::OnMouseReleased(const views::MouseEvent& event) { |
+ if (close_button_rect_.Contains(event.location())) |
+ GetWidget()->Close(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// DialogFrameView, private: |
+ |
+int DialogFrameView::GetNonClientTopHeight() const { |
+ return kDialogPadding + title_font_->GetHeight() + kDialogContentVSpacing; |
+} |
+ |
+} // namespace internal |
+} // namespace views |
Property changes on: ash\wm\dialog_frame_view.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |