summaryrefslogtreecommitdiffstats
path: root/ash/test
diff options
context:
space:
mode:
authortapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-29 19:49:44 +0000
committertapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-29 19:49:44 +0000
commit4baf67f8c9ee8cf5ce442b845338438a4b87fcac (patch)
tree270da7b7aa362d3045b071b890f33ce32e7765f4 /ash/test
parentb2360b158e12e9a3df97784360f1c97831ece796 (diff)
downloadchromium_src-4baf67f8c9ee8cf5ce442b845338438a4b87fcac.zip
chromium_src-4baf67f8c9ee8cf5ce442b845338438a4b87fcac.tar.gz
chromium_src-4baf67f8c9ee8cf5ce442b845338438a4b87fcac.tar.bz2
MacViews: Minimal to get views_unittests to compile.
- ui/views/test/child_modal_window.{h,cc} is moved from views_test_support to ash_test_support - test_views_delegate.cc is moved to test_views_delegate_aura.cc and a mac version added - the set of unittest.cc files that need refactoring for Aura are left off for mac to be enabled in a followup - http://crbug.com/378134 - a few other small fixes BUG=366007 Review URL: https://codereview.chromium.org/303473010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273554 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/test')
-rw-r--r--ash/test/child_modal_window.cc220
-rw-r--r--ash/test/child_modal_window.h80
2 files changed, 300 insertions, 0 deletions
diff --git a/ash/test/child_modal_window.cc b/ash/test/child_modal_window.cc
new file mode 100644
index 0000000..793b1bf
--- /dev/null
+++ b/ash/test/child_modal_window.cc
@@ -0,0 +1,220 @@
+// Copyright 2014 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/test/child_modal_window.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "ui/aura/window.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/background.h"
+#include "ui/views/controls/button/label_button.h"
+#include "ui/views/controls/native/native_view_host.h"
+#include "ui/views/controls/textfield/textfield.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/widget/widget_delegate.h"
+#include "ui/wm/core/window_modality_controller.h"
+
+using views::Widget;
+
+namespace ash {
+namespace test {
+
+namespace {
+
+// Parent window size and position.
+const int kWindowLeft = 170;
+const int kWindowTop = 200;
+const int kWindowWidth = 400;
+const int kWindowHeight = 400;
+
+// Parent window layout.
+const int kButtonHeight = 35;
+const int kTextfieldHeight = 35;
+
+// Child window size.
+const int kChildWindowWidth = 330;
+const int kChildWindowHeight = 200;
+
+// Child window layout.
+const int kChildTextfieldLeft = 20;
+const int kChildTextfieldTop = 50;
+const int kChildTextfieldWidth = 290;
+const int kChildTextfieldHeight = 35;
+
+const SkColor kModalParentColor = SK_ColorWHITE;
+const SkColor kChildColor = SK_ColorWHITE;
+
+} // namespace
+
+void CreateChildModalParent(gfx::NativeView context) {
+ Widget::CreateWindowWithContextAndBounds(
+ new ChildModalParent(context),
+ context,
+ gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight))->Show();
+}
+
+
+class ChildModalWindow : public views::WidgetDelegateView {
+ public:
+ ChildModalWindow();
+ virtual ~ChildModalWindow();
+
+ private:
+ // Overridden from View:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+ virtual gfx::Size GetPreferredSize() const OVERRIDE;
+
+ // Overridden from WidgetDelegate:
+ virtual View* GetContentsView() OVERRIDE;
+ virtual base::string16 GetWindowTitle() const OVERRIDE;
+ virtual bool CanResize() const OVERRIDE;
+ virtual ui::ModalType GetModalType() const OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(ChildModalWindow);
+};
+
+ChildModalWindow::ChildModalWindow() {
+ views::Textfield* textfield = new views::Textfield;
+ AddChildView(textfield);
+ textfield->SetBounds(
+ kChildTextfieldLeft, kChildTextfieldTop,
+ kChildTextfieldWidth, kChildTextfieldHeight);
+}
+
+ChildModalWindow::~ChildModalWindow() {
+}
+
+void ChildModalWindow::OnPaint(gfx::Canvas* canvas) {
+ canvas->FillRect(GetLocalBounds(), kChildColor);
+}
+
+gfx::Size ChildModalWindow::GetPreferredSize() const {
+ return gfx::Size(kChildWindowWidth, kChildWindowHeight);
+}
+
+views::View* ChildModalWindow::GetContentsView() {
+ return this;
+}
+
+base::string16 ChildModalWindow::GetWindowTitle() const {
+ return base::ASCIIToUTF16("Examples: Child Modal Window");
+}
+
+bool ChildModalWindow::CanResize() const {
+ return false;
+}
+
+ui::ModalType ChildModalWindow::GetModalType() const {
+ return ui::MODAL_TYPE_CHILD;
+}
+
+ChildModalParent::ChildModalParent(gfx::NativeView context)
+ : button_(new views::LabelButton(this,
+ base::ASCIIToUTF16(
+ "Show/Hide Child Modal Window"))),
+ textfield_(new views::Textfield),
+ host_(new views::NativeViewHost),
+ modal_parent_(NULL),
+ child_(NULL) {
+ Widget* widget = new Widget;
+ Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
+ params.context = context;
+ widget->Init(params);
+ widget->GetRootView()->set_background(
+ views::Background::CreateSolidBackground(kModalParentColor));
+ modal_parent_ = widget->GetNativeView();
+ widget->GetNativeView()->SetName("ModalParent");
+ AddChildView(button_);
+ AddChildView(textfield_);
+ AddChildView(host_);
+}
+
+ChildModalParent::~ChildModalParent() {
+}
+
+void ChildModalParent::ShowChild() {
+ if (!child_)
+ child_ = CreateChild();
+ child_->Show();
+}
+
+gfx::NativeWindow ChildModalParent::GetModalParent() const {
+ return modal_parent_;
+}
+
+gfx::NativeWindow ChildModalParent::GetChild() const {
+ if (child_)
+ return child_->GetNativeView();
+ return NULL;
+}
+
+Widget* ChildModalParent::CreateChild() {
+ Widget* child = Widget::CreateWindowWithParent(
+ new ChildModalWindow, GetWidget()->GetNativeView());
+ wm::SetModalParent(child->GetNativeView(), GetModalParent());
+ child->AddObserver(this);
+ child->GetNativeView()->SetName("ChildModalWindow");
+ return child;
+}
+
+views::View* ChildModalParent::GetContentsView() {
+ return this;
+}
+
+base::string16 ChildModalParent::GetWindowTitle() const {
+ return base::ASCIIToUTF16("Examples: Child Modal Parent");
+}
+
+bool ChildModalParent::CanResize() const {
+ return false;
+}
+
+void ChildModalParent::DeleteDelegate() {
+ if (child_) {
+ child_->RemoveObserver(this);
+ child_->Close();
+ child_ = NULL;
+ }
+
+ delete this;
+}
+
+void ChildModalParent::Layout() {
+ int running_y = y();
+ button_->SetBounds(x(), running_y, width(), kButtonHeight);
+ running_y += kButtonHeight;
+ textfield_->SetBounds(x(), running_y, width(), kTextfieldHeight);
+ running_y += kTextfieldHeight;
+ host_->SetBounds(x(), running_y, width(), height() - running_y);
+}
+
+void ChildModalParent::ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) {
+ if (details.is_add && details.child == this) {
+ host_->Attach(modal_parent_);
+ GetWidget()->GetNativeView()->SetName("Parent");
+ }
+}
+
+void ChildModalParent::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ if (sender == button_) {
+ if (!child_)
+ child_ = CreateChild();
+ if (child_->IsVisible())
+ child_->Hide();
+ else
+ child_->Show();
+ }
+}
+
+void ChildModalParent::OnWidgetDestroying(Widget* widget) {
+ if (child_) {
+ DCHECK_EQ(child_, widget);
+ child_ = NULL;
+ }
+}
+
+} // namespace test
+} // namespace ash
diff --git a/ash/test/child_modal_window.h b/ash/test/child_modal_window.h
new file mode 100644
index 0000000..ed8553a
--- /dev/null
+++ b/ash/test/child_modal_window.h
@@ -0,0 +1,80 @@
+// Copyright 2014 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_TEST_CHILD_MODAL_WINDOW_H_
+#define ASH_TEST_CHILD_MODAL_WINDOW_H_
+
+#include "ui/views/controls/button/button.h"
+#include "ui/views/widget/widget_delegate.h"
+#include "ui/views/widget/widget_observer.h"
+
+namespace views {
+class LabelButton;
+class NativeViewHost;
+class Textfield;
+class View;
+class Widget;
+}
+
+namespace ash {
+namespace test {
+
+void CreateChildModalParent(gfx::NativeView context);
+
+class ChildModalParent : public views::WidgetDelegateView,
+ public views::ButtonListener,
+ public views::WidgetObserver {
+ public:
+ ChildModalParent(gfx::NativeView context);
+ virtual ~ChildModalParent();
+
+ void ShowChild();
+ gfx::NativeWindow GetModalParent() const;
+ gfx::NativeWindow GetChild() const;
+
+ private:
+ views::Widget* CreateChild();
+
+ // Overridden from views::WidgetDelegate:
+ virtual View* GetContentsView() OVERRIDE;
+ virtual base::string16 GetWindowTitle() const OVERRIDE;
+ virtual bool CanResize() const OVERRIDE;
+ virtual void DeleteDelegate() OVERRIDE;
+
+ // Overridden from views::View:
+ virtual void Layout() OVERRIDE;
+ virtual void ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) OVERRIDE;
+
+ // Overridden from ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE;
+
+ // Overridden from WidgetObserver:
+ virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
+
+ // The button to toggle showing and hiding the child window. The child window
+ // does not block input to this button.
+ views::LabelButton* button_;
+
+ // The text field to indicate the keyboard focus.
+ views::Textfield* textfield_;
+
+ // The host for the modal parent.
+ views::NativeViewHost* host_;
+
+ // The modal parent of the child window. The child window blocks input to this
+ // view.
+ gfx::NativeWindow modal_parent_;
+
+ // The child window.
+ views::Widget* child_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChildModalParent);
+};
+
+} // namespace test
+} // namespace ash
+
+#endif // ASH_TEST_CHILD_MODAL_WINDOW_H_