diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-11 05:11:46 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-11 05:11:46 +0000 |
commit | 57b8bb357db85d85157c3a87f0b87383343867d8 (patch) | |
tree | 86094bfd85db4f416cbab9567fade0ec22d09e05 /ash | |
parent | adbc48a264898944041e1c2e0a794756bb8db3d5 (diff) | |
download | chromium_src-57b8bb357db85d85157c3a87f0b87383343867d8.zip chromium_src-57b8bb357db85d85157c3a87f0b87383343867d8.tar.gz chromium_src-57b8bb357db85d85157c3a87f0b87383343867d8.tar.bz2 |
Allow a Views client to provide a default frameview for window widgets.
Provides a default one in Ash that will be used to match kennedy-spec.
Much tweaking is needed, but that can come in future CLs.
http://crbug.com/109138
TEST=none
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=117165
Review URL: http://codereview.chromium.org/9166014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117170 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/ash_switches.cc | 3 | ||||
-rw-r--r-- | ash/ash_switches.h | 1 | ||||
-rw-r--r-- | ash/shell.cc | 10 | ||||
-rw-r--r-- | ash/shell.h | 9 | ||||
-rw-r--r-- | ash/shell/shell_main.cc | 17 | ||||
-rw-r--r-- | ash/wm/dialog_frame_view.cc | 140 | ||||
-rw-r--r-- | ash/wm/dialog_frame_view.h | 58 | ||||
-rw-r--r-- | ash/wm/modal_container_layout_manager.cc | 12 |
9 files changed, 250 insertions, 2 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 3bc383e..32d9cbb 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -107,6 +107,8 @@ 'wm/default_container_event_filter.h', 'wm/default_container_layout_manager.cc', 'wm/default_container_layout_manager.h', + 'wm/dialog_frame_view.cc', + 'wm/dialog_frame_view.h', 'wm/image_grid.cc', 'wm/image_grid.h', 'wm/modal_container_layout_manager.cc', diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 8ffd94b..30857a8 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -11,6 +11,9 @@ namespace ash { namespace switches { +// Use Google-style dialog box frames. +const char kAuraGoogleDialogFrames[] = "aura-google-dialog-frames"; + // Avoid drawing drop shadows under windows. const char kAuraNoShadows[] = "aura-no-shadows"; diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 2480bb6..65ba77d 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -12,6 +12,7 @@ namespace ash { namespace switches { // Please keep alphabetized. +ASH_EXPORT extern const char kAuraGoogleDialogFrames[]; ASH_EXPORT extern const char kAuraNoShadows[]; ASH_EXPORT extern const char kAuraTranslucentFrames[]; ASH_EXPORT extern const char kAuraViewsAppList[]; diff --git a/ash/shell.cc b/ash/shell.cc index c2e04fe..7d9863e 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -22,6 +22,7 @@ #include "ash/wm/compact_status_area_layout_manager.h" #include "ash/wm/default_container_event_filter.h" #include "ash/wm/default_container_layout_manager.h" +#include "ash/wm/dialog_frame_view.h" #include "ash/wm/modal_container_layout_manager.h" #include "ash/wm/power_button_controller.h" #include "ash/wm/root_window_event_filter.h" @@ -394,6 +395,15 @@ bool Shell::IsModalWindowOpen() const { return !modal_container->children().empty(); } +views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( + views::Widget* widget) { + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAuraGoogleDialogFrames)) { + return new internal::DialogFrameView; + } + return NULL; +} + //////////////////////////////////////////////////////////////////////////////// // Shell, private: diff --git a/ash/shell.h b/ash/shell.h index 037b66f..7bb5d0b 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -27,6 +27,10 @@ namespace gfx { class Rect; class Size; } +namespace views { +class NonClientFrameView; +class Widget; +} namespace ash { @@ -88,6 +92,11 @@ class ASH_EXPORT Shell { // See enum WindowMode for details. bool IsWindowModeCompact() const { return window_mode_ == COMPACT_MODE; } + // Creates a default views::NonClientFrameView for use by windows in the + // Ash environment. + views::NonClientFrameView* CreateDefaultNonClientFrameView( + views::Widget* widget); + AcceleratorController* accelerator_controller() { return accelerator_controller_.get(); } diff --git a/ash/shell/shell_main.cc b/ash/shell/shell_main.cc index acbf788..5619d00 100644 --- a/ash/shell/shell_main.cc +++ b/ash/shell/shell_main.cc @@ -26,6 +26,21 @@ namespace { +class ShellViewsDelegate : public views::TestViewsDelegate { + public: + ShellViewsDelegate() {} + virtual ~ShellViewsDelegate() {} + + // Overridden from views::TestViewsDelegate: + virtual views::NonClientFrameView* CreateDefaultNonClientFrameView( + views::Widget* widget) OVERRIDE { + return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(widget); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate); +}; + class ShellDelegateImpl : public ash::ShellDelegate { public: ShellDelegateImpl() { @@ -116,7 +131,7 @@ int main(int argc, char** argv) { // A ViewsDelegate is required. if (!views::ViewsDelegate::views_delegate) - views::ViewsDelegate::views_delegate = new views::TestViewsDelegate; + views::ViewsDelegate::views_delegate = new ShellViewsDelegate; ash::Shell::CreateInstance(new ShellDelegateImpl); diff --git a/ash/wm/dialog_frame_view.cc b/ash/wm/dialog_frame_view.cc new file mode 100644 index 0000000..80bc098 --- /dev/null +++ b/ash/wm/dialog_frame_view.cc @@ -0,0 +1,140 @@ +// 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/base/hit_test.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 Google-style. +// 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. +// |kDialogPadding| is the standardized padding amount, the specific per-side +// padding values are offset from this to achieve a uniform look with our +// existing code. +static int kDialogPadding = 30; +static int kDialogHPadding = kDialogPadding - 13; +static int kDialogTopPadding = kDialogPadding; +static int kDialogBottomPadding = kDialogPadding - 10; +static int kDialogContentVSpacing = 5; + +const int kCloseButtonSize = 16; + +//////////////////////////////////////////////////////////////////////////////// +// DialogFrameView, public: + +DialogFrameView::DialogFrameView() { + set_background(views::Background::CreateSolidBackground( + kDialogBackgroundColor)); + 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(kDialogHPadding, GetNonClientTopHeight(), + kDialogHPadding, kDialogBottomPadding); + return client_bounds; +} + +gfx::Rect DialogFrameView::GetWindowBoundsForClientBounds( + const gfx::Rect& client_bounds) const { + gfx::Rect window_bounds = client_bounds; + window_bounds.Inset(-kDialogHPadding, -GetNonClientTopHeight(), + -kDialogHPadding, -kDialogBottomPadding); + 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, + kDialogTopPadding, kCloseButtonSize, + kCloseButtonSize); + title_display_rect_.Inset(kDialogPadding, kDialogTopPadding, + kDialogPadding + kCloseButtonSize, + kDialogBottomPadding); + 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 kDialogTopPadding + title_font_->GetHeight() + kDialogContentVSpacing; +} + +} // namespace internal +} // namespace views diff --git a/ash/wm/dialog_frame_view.h b/ash/wm/dialog_frame_view.h new file mode 100644 index 0000000..1a89f39 --- /dev/null +++ b/ash/wm/dialog_frame_view.h @@ -0,0 +1,58 @@ +// 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. + +#ifndef ASH_WM_DIALOG_FRAME_VIEW_H_ +#define ASH_WM_DIALOG_FRAME_VIEW_H_ +#pragma once + +#include "ui/views/window/non_client_view.h" + +namespace gfx { +class Font; +} + +namespace ash { +namespace internal { + +// A NonClientFrameView that implements a Google-style for dialogs. +class DialogFrameView : public views::NonClientFrameView { + public: + // Internal class name. + static const char kViewClassName[]; + + DialogFrameView(); + virtual ~DialogFrameView(); + + // Overridden from views::NonClientFrameView: + virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; + virtual gfx::Rect GetWindowBoundsForClientBounds( + const gfx::Rect& client_bounds) const OVERRIDE; + virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; + virtual void GetWindowMask(const gfx::Size& size, + gfx::Path* window_mask) OVERRIDE; + virtual void ResetWindowControls() OVERRIDE; + virtual void UpdateWindowIcon() OVERRIDE; + + // Overridden from View: + virtual std::string GetClassName() const OVERRIDE; + virtual void Layout() OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; + + private: + int GetNonClientTopHeight() const; + + gfx::Rect title_display_rect_; + gfx::Rect close_button_rect_; + + static gfx::Font* title_font_; + + DISALLOW_COPY_AND_ASSIGN(DialogFrameView); +}; + +} // namespace internal +} // namespace views + +#endif // ASH_WM_DIALOG_FRAME_VIEW_H_ diff --git a/ash/wm/modal_container_layout_manager.cc b/ash/wm/modal_container_layout_manager.cc index 589305e..e4b8ea4 100644 --- a/ash/wm/modal_container_layout_manager.cc +++ b/ash/wm/modal_container_layout_manager.cc @@ -4,10 +4,12 @@ #include "ash/wm/modal_container_layout_manager.h" +#include "ash/ash_switches.h" #include "ash/shell.h" #include "ash/wm/modality_event_filter.h" #include "ash/wm/window_util.h" #include "base/bind.h" +#include "base/command_line.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" @@ -30,10 +32,18 @@ class ScreenView : public views::View { // Overridden from views::View: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - canvas->FillRect(SK_ColorBLACK, GetLocalBounds()); + canvas->FillRect(GetOverlayColor(), GetLocalBounds()); } private: + SkColor GetOverlayColor() { + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAuraGoogleDialogFrames)) { + return SK_ColorWHITE; + } + return SK_ColorBLACK; + } + DISALLOW_COPY_AND_ASSIGN(ScreenView); }; |