diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 20:17:01 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 20:17:01 +0000 |
commit | ca9c23002e3e9d6325e6bddae60341f67dd4f460 (patch) | |
tree | d687c041da38970a6872e6b2e0c6543b083f01dd /ash/shell | |
parent | 240502342713279f648c1b21a889e52d19b91ff1 (diff) | |
download | chromium_src-ca9c23002e3e9d6325e6bddae60341f67dd4f460.zip chromium_src-ca9c23002e3e9d6325e6bddae60341f67dd4f460.tar.gz chromium_src-ca9c23002e3e9d6325e6bddae60341f67dd4f460.tar.bz2 |
Create the new toplevel directory ash, and move the shell examples in it as a seed.
Examples are now known as "shell". (I will rename aura_shell::Shell to something else in a pending CL).
http://crbug.com/108457
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/9026012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/shell')
-rw-r--r-- | ash/shell/bubble.cc | 48 | ||||
-rw-r--r-- | ash/shell/example_factory.h | 26 | ||||
-rw-r--r-- | ash/shell/lock_view.cc | 74 | ||||
-rw-r--r-- | ash/shell/shell_main.cc | 134 | ||||
-rw-r--r-- | ash/shell/toplevel_window.cc | 61 | ||||
-rw-r--r-- | ash/shell/toplevel_window.h | 46 | ||||
-rw-r--r-- | ash/shell/widgets.cc | 143 | ||||
-rw-r--r-- | ash/shell/window_type_launcher.cc | 318 | ||||
-rw-r--r-- | ash/shell/window_type_launcher.h | 80 |
9 files changed, 930 insertions, 0 deletions
diff --git a/ash/shell/bubble.cc b/ash/shell/bubble.cc new file mode 100644 index 0000000..0b14ad6 --- /dev/null +++ b/ash/shell/bubble.cc @@ -0,0 +1,48 @@ +// Copyright (c) 2011 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 "base/utf_string_conversions.h" +#include "ui/views/bubble/bubble_border.h" +#include "ui/views/bubble/bubble_delegate.h" +#include "ui/views/controls/label.h" +#include "ui/views/layout/fill_layout.h" +#include "ui/views/widget/widget.h" + +namespace ash { +namespace shell { + +struct BubbleConfig { + string16 label; + views::View* anchor_view; + views::BubbleBorder::ArrowLocation arrow; +}; + +class ExampleBubbleDelegateView : public views::BubbleDelegateView { + public: + ExampleBubbleDelegateView(const BubbleConfig& config) + : BubbleDelegateView(config.anchor_view, config.arrow), + label_(config.label) {} + + virtual void Init() OVERRIDE { + SetLayoutManager(new views::FillLayout()); + views::Label* label = new views::Label(label_); + AddChildView(label); + } + + private: + string16 label_; +}; + +void CreatePointyBubble(views::View* anchor_view) { + BubbleConfig config; + config.label = ASCIIToUTF16("PointyBubble"); + config.anchor_view = anchor_view; + config.arrow = views::BubbleBorder::TOP_LEFT; + ExampleBubbleDelegateView* bubble = new ExampleBubbleDelegateView(config); + views::BubbleDelegateView::CreateBubble(bubble); + bubble->Show(); +} + +} // namespace shell +} // namespace ash diff --git a/ash/shell/example_factory.h b/ash/shell/example_factory.h new file mode 100644 index 0000000..25491ac --- /dev/null +++ b/ash/shell/example_factory.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 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_SHELL_EXAMPLE_FACTORY_H_ +#define ASH_SHELL_EXAMPLE_FACTORY_H_ +#pragma once + +namespace views { +class View; +} + +namespace ash { +namespace shell { + +void CreatePointyBubble(views::View* anchor_view); + +void CreateLockScreen(); + +// Creates a window showing samples of commonly used widgets. +void CreateWidgetsWindow(); + +} // namespace shell +} // namespace ash + +#endif // ASH_SHELL_EXAMPLE_FACTORY_H_ diff --git a/ash/shell/lock_view.cc b/ash/shell/lock_view.cc new file mode 100644 index 0000000..641734f --- /dev/null +++ b/ash/shell/lock_view.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2011 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/shell/example_factory.h" +#include "base/utf_string_conversions.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/aura_shell/shell.h" +#include "ui/aura_shell/shell_window_ids.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/font.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" + +using aura_shell::Shell; + +namespace ash { +namespace shell { + +class LockView : public views::WidgetDelegateView { + public: + LockView() {} + virtual ~LockView() {} + + // Overridden from View: + virtual gfx::Size GetPreferredSize() OVERRIDE { + return gfx::Size(500, 400); + } + + private: + // Overridden from View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { + canvas->FillRect(SK_ColorYELLOW, GetLocalBounds()); + string16 text = ASCIIToUTF16("LOCKED!"); + int string_width = font_.GetStringWidth(text); + canvas->DrawStringInt(text, font_, SK_ColorRED, (width() - string_width)/ 2, + (height() - font_.GetHeight()) / 2, + string_width, font_.GetHeight()); + } + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { + return true; + } + virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE { + GetWidget()->Close(); + } + + gfx::Font font_; + + DISALLOW_COPY_AND_ASSIGN(LockView); +}; + +void CreateLockScreen() { + LockView* lock_view = new LockView; + views::Widget* widget = new views::Widget; + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + gfx::Size ps = lock_view->GetPreferredSize(); + + gfx::Size root_window_size = aura::RootWindow::GetInstance()->GetHostSize(); + params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2, + (root_window_size.height() - ps.height()) / 2, + ps.width(), ps.height()); + params.delegate = lock_view; + widget->Init(params); + Shell::GetInstance()->GetContainer( + aura_shell::internal::kShellWindowId_LockScreenContainer)-> + AddChild(widget->GetNativeView()); + widget->SetContentsView(lock_view); + widget->Show(); + widget->GetNativeView()->SetName("LockView"); +} + +} // namespace shell +} // namespace ash diff --git a/ash/shell/shell_main.cc b/ash/shell/shell_main.cc new file mode 100644 index 0000000..1042ec3 --- /dev/null +++ b/ash/shell/shell_main.cc @@ -0,0 +1,134 @@ +// Copyright (c) 2011 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/shell/toplevel_window.h" +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/i18n/icu_util.h" +#include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" +#include "ui/aura/root_window.h" +#include "ui/aura_shell/launcher/launcher_types.h" +#include "ui/aura_shell/shell.h" +#include "ui/aura_shell/shell_delegate.h" +#include "ui/aura_shell/shell_factory.h" +#include "ui/aura_shell/window_util.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_paths.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/compositor/test/compositor_test_support.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" + +namespace { + +class AppListWindow : public views::WidgetDelegateView { + public: + AppListWindow() { + } + + // static + static views::Widget* Create(const gfx::Rect& bounds) { + AppListWindow* app_list = new AppListWindow; + + views::Widget::InitParams widget_params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + widget_params.bounds = bounds; + widget_params.delegate = app_list; + widget_params.keep_on_top = true; + widget_params.transparent = true; + + views::Widget* widget = new views::Widget; + widget->Init(widget_params); + widget->SetContentsView(app_list); + return widget; + } + + // Overridden from views::View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { + canvas->FillRect(SkColorSetARGB(0x4F, 0xFF, 0, 0), bounds()); + } +}; + +class ShellDelegateImpl : public aura_shell::ShellDelegate { + public: + ShellDelegateImpl() { + } + + virtual void CreateNewWindow() OVERRIDE { + ash::shell::ToplevelWindow::CreateParams create_params; + create_params.can_resize = true; + create_params.can_maximize = true; + ash::shell::ToplevelWindow::CreateToplevelWindow(create_params); + } + + virtual views::Widget* CreateStatusArea() OVERRIDE { + return aura_shell::internal::CreateStatusArea(); + } + + virtual void RequestAppListWidget( + const gfx::Rect& bounds, + const SetWidgetCallback& callback) OVERRIDE { + callback.Run(AppListWindow::Create(bounds)); + } + + virtual void LauncherItemClicked( + const aura_shell::LauncherItem& item) OVERRIDE { + aura_shell::ActivateWindow(item.window); + } + + virtual bool ConfigureLauncherItem(aura_shell::LauncherItem* item) OVERRIDE { + static int image_count = 0; + item->tab_images.resize(image_count + 1); + for (int i = 0; i < image_count + 1; ++i) { + item->tab_images[i].image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); + item->tab_images[i].image.allocPixels(); + item->tab_images[i].image.eraseARGB(255, + i == 0 ? 255 : 0, + i == 1 ? 255 : 0, + i == 2 ? 255 : 0); + } + image_count = (image_count + 1) % 3; + return true; // Makes the entry show up in the launcher. + } +}; + +} // namespace + +namespace ash { +namespace shell { + +void InitWindowTypeLauncher(); + +} // namespace shell +} // namespace ash + +int main(int argc, char** argv) { + CommandLine::Init(argc, argv); + + // The exit manager is in charge of calling the dtors of singleton objects. + base::AtExitManager exit_manager; + + ui::RegisterPathProvider(); + icu_util::Initialize(); + ResourceBundle::InitSharedInstance("en-US"); + + // Create the message-loop here before creating the root window. + MessageLoop message_loop(MessageLoop::TYPE_UI); + ui::CompositorTestSupport::Initialize(); + + aura_shell::Shell::CreateInstance(new ShellDelegateImpl); + + ash::shell::InitWindowTypeLauncher(); + + aura::RootWindow::GetInstance()->Run(); + + aura_shell::Shell::DeleteInstance(); + + aura::RootWindow::DeleteInstance(); + + ui::CompositorTestSupport::Terminate(); + + return 0; +} diff --git a/ash/shell/toplevel_window.cc b/ash/shell/toplevel_window.cc new file mode 100644 index 0000000..ba0e931 --- /dev/null +++ b/ash/shell/toplevel_window.cc @@ -0,0 +1,61 @@ +// Copyright (c) 2011 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/shell/toplevel_window.h" + +#include "base/utf_string_conversions.h" +#include "ui/aura/window.h" +#include "ui/aura_shell/toplevel_frame_view.h" +#include "ui/gfx/canvas.h" +#include "ui/views/widget/widget.h" + +namespace ash { +namespace shell { + +ToplevelWindow::CreateParams::CreateParams() + : can_resize(false), + can_maximize(false) { +} + +// static +void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) { + views::Widget* widget = + views::Widget::CreateWindowWithBounds(new ToplevelWindow(params), + gfx::Rect(120, 150, 400, 300)); + widget->GetNativeView()->SetName("Examples:ToplevelWindow"); + widget->Show(); +} + +ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) { +} + +ToplevelWindow::~ToplevelWindow() { +} + +void ToplevelWindow::OnPaint(gfx::Canvas* canvas) { + canvas->FillRect(SK_ColorDKGRAY, GetLocalBounds()); +} + +string16 ToplevelWindow::GetWindowTitle() const { + return ASCIIToUTF16("Examples: Toplevel Window"); +} + +views::View* ToplevelWindow::GetContentsView() { + return this; +} + +bool ToplevelWindow::CanResize() const { + return params_.can_resize; +} + +bool ToplevelWindow::CanMaximize() const { + return params_.can_maximize; +} + +views::NonClientFrameView* ToplevelWindow::CreateNonClientFrameView() { + return new aura_shell::internal::ToplevelFrameView; +} + +} // namespace shell +} // namespace ash diff --git a/ash/shell/toplevel_window.h b/ash/shell/toplevel_window.h new file mode 100644 index 0000000..08f493d --- /dev/null +++ b/ash/shell/toplevel_window.h @@ -0,0 +1,46 @@ +// Copyright (c) 2011 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_SHELL_TOPLEVEL_WINDOW_H_ +#define ASH_SHELL_TOPLEVEL_WINDOW_H_ +#pragma once + +#include "ui/views/widget/widget_delegate.h" + +namespace ash { +namespace shell { + +class ToplevelWindow : public views::WidgetDelegateView { + public: + struct CreateParams { + CreateParams(); + + bool can_resize; + bool can_maximize; + }; + static void CreateToplevelWindow(const CreateParams& params); + + private: + explicit ToplevelWindow(const CreateParams& params); + virtual ~ToplevelWindow(); + + // Overridden from views::View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + + // Overridden from views::WidgetDelegate: + virtual string16 GetWindowTitle() const OVERRIDE; + virtual View* GetContentsView() OVERRIDE; + virtual bool CanResize() const OVERRIDE; + virtual bool CanMaximize() const OVERRIDE; + virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE; + + const CreateParams params_; + + DISALLOW_COPY_AND_ASSIGN(ToplevelWindow); +}; + +} // namespace shell +} // namespace ash + +#endif // ASH_SHELL_TOPLEVEL_WINDOW_H_ diff --git a/ash/shell/widgets.cc b/ash/shell/widgets.cc new file mode 100644 index 0000000..24c5e8c --- /dev/null +++ b/ash/shell/widgets.cc @@ -0,0 +1,143 @@ +// Copyright (c) 2011 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 "base/utf_string_conversions.h" // ASCIIToUTF16 +#include "ui/aura/window.h" +#include "ui/aura_shell/toplevel_frame_view.h" +#include "ui/gfx/canvas.h" +#include "ui/views/controls/button/checkbox.h" +#include "ui/views/controls/button/radio_button.h" +#include "ui/views/controls/button/text_button.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" + +namespace { + +// Default window position. +const int kWindowLeft = 170; +const int kWindowTop = 200; + +// Default window size. +const int kWindowWidth = 400; +const int kWindowHeight = 400; + +// A window showing samples of commonly used widgets. +class WidgetsWindow : public views::WidgetDelegateView { + public: + WidgetsWindow(); + virtual ~WidgetsWindow(); + + // Overridden from views::View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual void Layout() OVERRIDE; + virtual gfx::Size GetPreferredSize() OVERRIDE; + + // Overridden from views::WidgetDelegate: + virtual views::View* GetContentsView() OVERRIDE; + virtual string16 GetWindowTitle() const OVERRIDE; + virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE; + + private: + views::NativeTextButton* button_; + views::NativeTextButton* disabled_button_; + views::Checkbox* checkbox_; + views::Checkbox* checkbox_disabled_; + views::Checkbox* checkbox_checked_; + views::Checkbox* checkbox_checked_disabled_; + views::RadioButton* radio_button_; + views::RadioButton* radio_button_disabled_; + views::RadioButton* radio_button_selected_; + views::RadioButton* radio_button_selected_disabled_; +}; + +WidgetsWindow::WidgetsWindow() + : button_(new views::NativeTextButton(NULL, ASCIIToUTF16("Button"))), + disabled_button_( + new views::NativeTextButton(NULL, ASCIIToUTF16("Disabled button"))), + checkbox_(new views::Checkbox(ASCIIToUTF16("Checkbox"))), + checkbox_disabled_(new views::Checkbox( + ASCIIToUTF16("Checkbox disabled"))), + checkbox_checked_(new views::Checkbox(ASCIIToUTF16("Checkbox checked"))), + checkbox_checked_disabled_(new views::Checkbox( + ASCIIToUTF16("Checkbox checked disabled"))), + radio_button_(new views::RadioButton(ASCIIToUTF16("Radio button"), 0)), + radio_button_disabled_(new views::RadioButton( + ASCIIToUTF16("Radio button disabled"), 0)), + radio_button_selected_(new views::RadioButton( + ASCIIToUTF16("Radio button selected"), 0)), + radio_button_selected_disabled_(new views::RadioButton( + ASCIIToUTF16("Radio button selected disabled"), 1)) { + AddChildView(button_); + disabled_button_->SetEnabled(false); + AddChildView(disabled_button_); + AddChildView(checkbox_); + checkbox_disabled_->SetEnabled(false); + AddChildView(checkbox_disabled_); + checkbox_checked_->SetChecked(true); + AddChildView(checkbox_checked_); + checkbox_checked_disabled_->SetChecked(true); + checkbox_checked_disabled_->SetEnabled(false); + AddChildView(checkbox_checked_disabled_); + AddChildView(radio_button_); + radio_button_disabled_->SetEnabled(false); + AddChildView(radio_button_disabled_); + radio_button_selected_->SetChecked(true); + AddChildView(radio_button_selected_); + radio_button_selected_disabled_->SetChecked(true); + radio_button_selected_disabled_->SetEnabled(false); + AddChildView(radio_button_selected_disabled_); +} + +WidgetsWindow::~WidgetsWindow() { +} + +void WidgetsWindow::OnPaint(gfx::Canvas* canvas) { + canvas->FillRect(SK_ColorWHITE, GetLocalBounds()); +} + +void WidgetsWindow::Layout() { + const int kVerticalPad = 5; + int left = 5; + int top = kVerticalPad; + for (Views::const_iterator it = children_begin(); + it != children_end(); + ++it) { + views::View* view = *it; + gfx::Size preferred = view->GetPreferredSize(); + view->SetBounds(left, top, preferred.width(), preferred.height()); + top += preferred.height() + kVerticalPad; + } +} + +gfx::Size WidgetsWindow::GetPreferredSize() { + return gfx::Size(kWindowWidth, kWindowHeight); +} + +views::View* WidgetsWindow::GetContentsView() { + return this; +} + +string16 WidgetsWindow::GetWindowTitle() const { + return ASCIIToUTF16("Examples: Widgets"); +} + +views::NonClientFrameView* WidgetsWindow::CreateNonClientFrameView() { + return new aura_shell::internal::ToplevelFrameView; +} + +} // namespace + +namespace ash { +namespace shell { + +void CreateWidgetsWindow() { + gfx::Rect bounds(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight); + views::Widget* widget = + views::Widget::CreateWindowWithBounds(new WidgetsWindow, bounds); + widget->GetNativeView()->SetName("WidgetsWindow"); + widget->Show(); +} + +} // namespace shell +} // namespace ash diff --git a/ash/shell/window_type_launcher.cc b/ash/shell/window_type_launcher.cc new file mode 100644 index 0000000..e839719 --- /dev/null +++ b/ash/shell/window_type_launcher.cc @@ -0,0 +1,318 @@ +// Copyright (c) 2011 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/shell/window_type_launcher.h" + +#include "ash/shell/example_factory.h" +#include "ash/shell/toplevel_window.h" +#include "base/utf_string_conversions.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/aura_shell/shadow_types.h" +#include "ui/aura_shell/shell_window_ids.h" +#include "ui/aura_shell/toplevel_frame_view.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/compositor/layer.h" +#include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/menu/menu_item_view.h" +#include "ui/views/controls/menu/menu_runner.h" +#include "ui/views/examples/examples_window.h" +#include "ui/views/widget/widget.h" + +using views::MenuItemView; +using views::MenuRunner; + +namespace ash { +namespace shell { + +namespace { + +SkColor g_colors[] = { SK_ColorRED, + SK_ColorYELLOW, + SK_ColorBLUE, + SK_ColorGREEN }; +int g_color_index = 0; + +class ModalWindow : public views::WidgetDelegateView, + public views::ButtonListener { + public: + ModalWindow() + : color_(g_colors[g_color_index]), + ALLOW_THIS_IN_INITIALIZER_LIST(open_button_( + new views::NativeTextButton(this, ASCIIToUTF16("Moar!")))) { + ++g_color_index %= arraysize(g_colors); + AddChildView(open_button_); + } + virtual ~ModalWindow() { + } + + static void OpenModalWindow(aura::Window* parent) { + views::Widget* widget = + views::Widget::CreateWindowWithParent(new ModalWindow, parent); + widget->GetNativeView()->SetName("ModalWindow"); + widget->Show(); + } + + // Overridden from views::View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { + canvas->FillRect(color_, GetLocalBounds()); + } + virtual gfx::Size GetPreferredSize() OVERRIDE { + return gfx::Size(200, 200); + } + virtual void Layout() OVERRIDE { + gfx::Size open_ps = open_button_->GetPreferredSize(); + gfx::Rect local_bounds = GetLocalBounds(); + open_button_->SetBounds( + 5, local_bounds.bottom() - open_ps.height() - 5, + open_ps.width(), open_ps.height()); + } + + // Overridden from views::WidgetDelegate: + virtual views::View* GetContentsView() OVERRIDE { + return this; + } + virtual bool CanResize() const OVERRIDE { + return true; + } + virtual string16 GetWindowTitle() const OVERRIDE { + return ASCIIToUTF16("Modal Window"); + } + virtual bool IsModal() const OVERRIDE { + return true; + } + + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, + const views::Event& event) OVERRIDE { + DCHECK(sender == open_button_); + OpenModalWindow(GetWidget()->GetNativeView()); + } + + private: + SkColor color_; + views::NativeTextButton* open_button_; + + DISALLOW_COPY_AND_ASSIGN(ModalWindow); +}; + +class NonModalTransient : public views::WidgetDelegateView { + public: + NonModalTransient() + : color_(g_colors[g_color_index]) { + ++g_color_index %= arraysize(g_colors); + } + virtual ~NonModalTransient() { + } + + static void OpenNonModalTransient(aura::Window* parent) { + views::Widget* widget = + views::Widget::CreateWindowWithParent(new NonModalTransient, parent); + widget->GetNativeView()->SetName("NonModalTransient"); + widget->Show(); + } + + // Overridden from views::View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { + canvas->FillRect(color_, GetLocalBounds()); + } + virtual gfx::Size GetPreferredSize() OVERRIDE { + return gfx::Size(250, 250); + } + + // Overridden from views::WidgetDelegate: + virtual views::View* GetContentsView() OVERRIDE { + return this; + } + virtual bool CanResize() const OVERRIDE { + return true; + } + virtual string16 GetWindowTitle() const OVERRIDE { + return ASCIIToUTF16("Non-Modal Transient"); + } + + private: + SkColor color_; + + DISALLOW_COPY_AND_ASSIGN(NonModalTransient); +}; + +} // namespace + +void InitWindowTypeLauncher() { + views::Widget* widget = + views::Widget::CreateWindowWithBounds(new WindowTypeLauncher, + gfx::Rect(120, 150, 400, 300)); + widget->GetNativeView()->SetName("WindowTypeLauncher"); + aura_shell::internal::SetShadowType(widget->GetNativeView(), + aura_shell::internal::SHADOW_TYPE_NONE); + widget->Show(); +} + +WindowTypeLauncher::WindowTypeLauncher() + : ALLOW_THIS_IN_INITIALIZER_LIST(create_button_( + new views::NativeTextButton(this, ASCIIToUTF16("Create Window")))), + ALLOW_THIS_IN_INITIALIZER_LIST(create_nonresizable_button_( + new views::NativeTextButton( + this, ASCIIToUTF16("Create Non-Resizable Window")))), + ALLOW_THIS_IN_INITIALIZER_LIST(bubble_button_( + new views::NativeTextButton( + this, ASCIIToUTF16("Create Pointy Bubble")))), + ALLOW_THIS_IN_INITIALIZER_LIST(lock_button_( + new views::NativeTextButton(this, ASCIIToUTF16("Lock Screen")))), + ALLOW_THIS_IN_INITIALIZER_LIST(widgets_button_( + new views::NativeTextButton( + this, ASCIIToUTF16("Show Example Widgets")))), + ALLOW_THIS_IN_INITIALIZER_LIST(modal_button_( + new views::NativeTextButton( + this, ASCIIToUTF16("Open Modal Window")))), + ALLOW_THIS_IN_INITIALIZER_LIST(transient_button_( + new views::NativeTextButton( + this, ASCIIToUTF16("Open Non-Modal Transient Window")))), + ALLOW_THIS_IN_INITIALIZER_LIST(examples_button_( + new views::NativeTextButton( + this, ASCIIToUTF16("Open Views Examples Window")))) { + AddChildView(create_button_); + AddChildView(create_nonresizable_button_); + AddChildView(bubble_button_); + AddChildView(lock_button_); + AddChildView(widgets_button_); + AddChildView(modal_button_); + AddChildView(transient_button_); + AddChildView(examples_button_); + set_context_menu_controller(this); +} + +WindowTypeLauncher::~WindowTypeLauncher() { +} + +void WindowTypeLauncher::OnPaint(gfx::Canvas* canvas) { + canvas->FillRect(SK_ColorWHITE, GetLocalBounds()); +} + +void WindowTypeLauncher::Layout() { + gfx::Size create_button_ps = create_button_->GetPreferredSize(); + gfx::Rect local_bounds = GetLocalBounds(); + create_button_->SetBounds( + 5, local_bounds.bottom() - create_button_ps.height() - 5, + create_button_ps.width(), create_button_ps.height()); + + gfx::Size bubble_button_ps = bubble_button_->GetPreferredSize(); + bubble_button_->SetBounds( + 5, create_button_->y() - bubble_button_ps.height() - 5, + bubble_button_ps.width(), bubble_button_ps.height()); + + gfx::Size create_nr_button_ps = + create_nonresizable_button_->GetPreferredSize(); + create_nonresizable_button_->SetBounds( + 5, bubble_button_->y() - create_nr_button_ps.height() - 5, + create_nr_button_ps.width(), create_nr_button_ps.height()); + + gfx::Size lock_ps = lock_button_->GetPreferredSize(); + lock_button_->SetBounds( + 5, create_nonresizable_button_->y() - lock_ps.height() - 5, + lock_ps.width(), lock_ps.height()); + + gfx::Size widgets_ps = widgets_button_->GetPreferredSize(); + widgets_button_->SetBounds( + 5, lock_button_->y() - widgets_ps.height() - 5, + widgets_ps.width(), widgets_ps.height()); + + gfx::Size modal_ps = modal_button_->GetPreferredSize(); + modal_button_->SetBounds( + 5, widgets_button_->y() - modal_ps.height() - 5, + modal_ps.width(), modal_ps.height()); + + gfx::Size transient_ps = transient_button_->GetPreferredSize(); + transient_button_->SetBounds( + 5, modal_button_->y() - transient_ps.height() - 5, + transient_ps.width(), transient_ps.height()); + + gfx::Size examples_ps = examples_button_->GetPreferredSize(); + examples_button_->SetBounds( + 5, transient_button_->y() - examples_ps.height() - 5, + examples_ps.width(), examples_ps.height()); +} + +gfx::Size WindowTypeLauncher::GetPreferredSize() { + return gfx::Size(300, 500); +} + +bool WindowTypeLauncher::OnMousePressed(const views::MouseEvent& event) { + // Overridden so we get OnMouseReleased and can show the context menu. + return true; +} + +views::View* WindowTypeLauncher::GetContentsView() { + return this; +} + +bool WindowTypeLauncher::CanResize() const { + return true; +} + +string16 WindowTypeLauncher::GetWindowTitle() const { + return ASCIIToUTF16("Examples: Window Builder"); +} + +views::NonClientFrameView* WindowTypeLauncher::CreateNonClientFrameView() { + return new aura_shell::internal::ToplevelFrameView; +} + +void WindowTypeLauncher::ButtonPressed(views::Button* sender, + const views::Event& event) { + if (sender == create_button_) { + ToplevelWindow::CreateParams params; + params.can_resize = true; + ToplevelWindow::CreateToplevelWindow(params); + } else if (sender == create_nonresizable_button_) { + ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams()); + } else if (sender == bubble_button_) { + CreatePointyBubble(sender); + } else if (sender == lock_button_) { + CreateLockScreen(); + } else if (sender == widgets_button_) { + CreateWidgetsWindow(); + } else if (sender == modal_button_) { + ModalWindow::OpenModalWindow(GetWidget()->GetNativeView()); + } else if (sender == transient_button_) { + NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView()); + } else if (sender == examples_button_) { + views::examples::ShowExamplesWindow(false); + } +} + +void WindowTypeLauncher::ExecuteCommand(int id) { + switch (id) { + case COMMAND_NEW_WINDOW: + InitWindowTypeLauncher(); + break; + case COMMAND_TOGGLE_FULLSCREEN: + GetWidget()->SetFullscreen(!GetWidget()->IsFullscreen()); + break; + default: + break; + } +} + +void WindowTypeLauncher::ShowContextMenuForView(views::View* source, + const gfx::Point& p, + bool is_mouse_gesture) { + MenuItemView* root = new MenuItemView(this); + root->AppendMenuItem(COMMAND_NEW_WINDOW, + ASCIIToUTF16("New Window"), + MenuItemView::NORMAL); + root->AppendMenuItem(COMMAND_TOGGLE_FULLSCREEN, + ASCIIToUTF16("Toggle FullScreen"), + MenuItemView::NORMAL); + // MenuRunner takes ownership of root. + menu_runner_.reset(new MenuRunner(root)); + if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(p, gfx::Size(0, 0)), + MenuItemView::TOPLEFT, + MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) + return; +} + +} // namespace shell +} // namespace ash diff --git a/ash/shell/window_type_launcher.h b/ash/shell/window_type_launcher.h new file mode 100644 index 0000000..5e7fd6f --- /dev/null +++ b/ash/shell/window_type_launcher.h @@ -0,0 +1,80 @@ +// Copyright (c) 2011 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_SHELL_WINDOW_TYPE_LAUNCHER_H_ +#define ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_ +#pragma once + +#include "ui/views/context_menu_controller.h" +#include "ui/views/controls/button/button.h" +#include "ui/views/controls/menu/menu_delegate.h" +#include "ui/views/widget/widget_delegate.h" + +namespace views { +class MenuRunner; +class NativeTextButton; +} + +namespace ash { +namespace shell { + +// The contents view/delegate of a window that shows some buttons that create +// various window types. +class WindowTypeLauncher : public views::WidgetDelegateView, + public views::ButtonListener, + public views::MenuDelegate, + public views::ContextMenuController { + public: + WindowTypeLauncher(); + virtual ~WindowTypeLauncher(); + + private: + typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; + + enum MenuCommands { + COMMAND_NEW_WINDOW = 1, + COMMAND_TOGGLE_FULLSCREEN = 3, + }; + + // Overridden from views::View: + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual void Layout() OVERRIDE; + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + + // Overridden from views::WidgetDelegate: + virtual views::View* GetContentsView() OVERRIDE; + virtual bool CanResize() const OVERRIDE; + virtual string16 GetWindowTitle() const OVERRIDE; + virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE; + + // Overridden from views::ButtonListener: + virtual void ButtonPressed(views::Button* sender, + const views::Event& event) OVERRIDE; + + // Overridden from views::MenuDelegate: + virtual void ExecuteCommand(int id) OVERRIDE; + + // Override from views::ContextMenuController: + virtual void ShowContextMenuForView(views::View* source, + const gfx::Point& p, + bool is_mouse_gesture) OVERRIDE; + + views::NativeTextButton* create_button_; + views::NativeTextButton* create_nonresizable_button_; + views::NativeTextButton* bubble_button_; + views::NativeTextButton* lock_button_; + views::NativeTextButton* widgets_button_; + views::NativeTextButton* modal_button_; + views::NativeTextButton* transient_button_; + views::NativeTextButton* examples_button_; + scoped_ptr<views::MenuRunner> menu_runner_; + + DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncher); +}; + +} // namespace shell +} // namespace ash + +#endif // ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_ |