Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: ash/shell/window_type_launcher.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shell/widgets.cc ('k') | ash/shell/window_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell/window_type_launcher.h" 5 #include "ash/shell/window_type_launcher.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shell_window_ids.h" 10 #include "ash/common/shell_window_ids.h"
(...skipping 24 matching lines...) Expand all
35 #include "ui/wm/core/shadow_types.h" 35 #include "ui/wm/core/shadow_types.h"
36 36
37 using views::MenuItemView; 37 using views::MenuItemView;
38 using views::MenuRunner; 38 using views::MenuRunner;
39 39
40 namespace ash { 40 namespace ash {
41 namespace shell { 41 namespace shell {
42 42
43 namespace { 43 namespace {
44 44
45 SkColor g_colors[] = { SK_ColorRED, 45 SkColor g_colors[] = {SK_ColorRED, SK_ColorYELLOW, SK_ColorBLUE, SK_ColorGREEN};
46 SK_ColorYELLOW,
47 SK_ColorBLUE,
48 SK_ColorGREEN };
49 int g_color_index = 0; 46 int g_color_index = 0;
50 47
51 class ModalWindow : public views::WidgetDelegateView, 48 class ModalWindow : public views::WidgetDelegateView,
52 public views::ButtonListener { 49 public views::ButtonListener {
53 public: 50 public:
54 explicit ModalWindow(ui::ModalType modal_type) 51 explicit ModalWindow(ui::ModalType modal_type)
55 : modal_type_(modal_type), 52 : modal_type_(modal_type),
56 color_(g_colors[g_color_index]), 53 color_(g_colors[g_color_index]),
57 open_button_(new views::LabelButton(this, 54 open_button_(
58 base::ASCIIToUTF16("Moar!"))) { 55 new views::LabelButton(this, base::ASCIIToUTF16("Moar!"))) {
59 ++g_color_index %= arraysize(g_colors); 56 ++g_color_index %= arraysize(g_colors);
60 open_button_->SetStyle(views::Button::STYLE_BUTTON); 57 open_button_->SetStyle(views::Button::STYLE_BUTTON);
61 AddChildView(open_button_); 58 AddChildView(open_button_);
62 } 59 }
63 ~ModalWindow() override {} 60 ~ModalWindow() override {}
64 61
65 static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) { 62 static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) {
66 views::Widget* widget = 63 views::Widget* widget = views::Widget::CreateWindowWithParent(
67 views::Widget::CreateWindowWithParent(new ModalWindow(modal_type), 64 new ModalWindow(modal_type), parent);
68 parent);
69 widget->GetNativeView()->SetName("ModalWindow"); 65 widget->GetNativeView()->SetName("ModalWindow");
70 widget->Show(); 66 widget->Show();
71 } 67 }
72 68
73 // Overridden from views::View: 69 // Overridden from views::View:
74 void OnPaint(gfx::Canvas* canvas) override { 70 void OnPaint(gfx::Canvas* canvas) override {
75 canvas->FillRect(GetLocalBounds(), color_); 71 canvas->FillRect(GetLocalBounds(), color_);
76 } 72 }
77 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); } 73 gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
78 void Layout() override { 74 void Layout() override {
79 gfx::Size open_ps = open_button_->GetPreferredSize(); 75 gfx::Size open_ps = open_button_->GetPreferredSize();
80 gfx::Rect local_bounds = GetLocalBounds(); 76 gfx::Rect local_bounds = GetLocalBounds();
81 open_button_->SetBounds( 77 open_button_->SetBounds(5, local_bounds.bottom() - open_ps.height() - 5,
82 5, local_bounds.bottom() - open_ps.height() - 5, 78 open_ps.width(), open_ps.height());
83 open_ps.width(), open_ps.height());
84 } 79 }
85 80
86 // Overridden from views::WidgetDelegate: 81 // Overridden from views::WidgetDelegate:
87 views::View* GetContentsView() override { return this; } 82 views::View* GetContentsView() override { return this; }
88 bool CanResize() const override { return true; } 83 bool CanResize() const override { return true; }
89 base::string16 GetWindowTitle() const override { 84 base::string16 GetWindowTitle() const override {
90 return base::ASCIIToUTF16("Modal Window"); 85 return base::ASCIIToUTF16("Modal Window");
91 } 86 }
92 ui::ModalType GetModalType() const override { return modal_type_; } 87 ui::ModalType GetModalType() const override { return modal_type_; }
93 88
94 // Overridden from views::ButtonListener: 89 // Overridden from views::ButtonListener:
95 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 90 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
96 DCHECK(sender == open_button_); 91 DCHECK(sender == open_button_);
97 OpenModalWindow(GetWidget()->GetNativeView(), modal_type_); 92 OpenModalWindow(GetWidget()->GetNativeView(), modal_type_);
98 } 93 }
99 94
100 private: 95 private:
101 ui::ModalType modal_type_; 96 ui::ModalType modal_type_;
102 SkColor color_; 97 SkColor color_;
103 views::LabelButton* open_button_; 98 views::LabelButton* open_button_;
104 99
105 DISALLOW_COPY_AND_ASSIGN(ModalWindow); 100 DISALLOW_COPY_AND_ASSIGN(ModalWindow);
106 }; 101 };
107 102
108 class NonModalTransient : public views::WidgetDelegateView { 103 class NonModalTransient : public views::WidgetDelegateView {
109 public: 104 public:
110 NonModalTransient() 105 NonModalTransient() : color_(g_colors[g_color_index]) {
111 : color_(g_colors[g_color_index]) {
112 ++g_color_index %= arraysize(g_colors); 106 ++g_color_index %= arraysize(g_colors);
113 } 107 }
114 ~NonModalTransient() override {} 108 ~NonModalTransient() override {}
115 109
116 static void OpenNonModalTransient(aura::Window* parent) { 110 static void OpenNonModalTransient(aura::Window* parent) {
117 views::Widget* widget = 111 views::Widget* widget =
118 views::Widget::CreateWindowWithParent(new NonModalTransient, parent); 112 views::Widget::CreateWindowWithParent(new NonModalTransient, parent);
119 widget->GetNativeView()->SetName("NonModalTransient"); 113 widget->GetNativeView()->SetName("NonModalTransient");
120 widget->Show(); 114 widget->Show();
121 } 115 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 158
165 void AddViewToLayout(views::GridLayout* layout, views::View* view) { 159 void AddViewToLayout(views::GridLayout* layout, views::View* view) {
166 layout->StartRow(0, 0); 160 layout->StartRow(0, 0);
167 layout->AddView(view); 161 layout->AddView(view);
168 layout->AddPaddingRow(0, 5); 162 layout->AddPaddingRow(0, 5);
169 } 163 }
170 164
171 } // namespace 165 } // namespace
172 166
173 void InitWindowTypeLauncher() { 167 void InitWindowTypeLauncher() {
174 views::Widget* widget = 168 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
175 views::Widget::CreateWindowWithContextAndBounds( 169 new WindowTypeLauncher, Shell::GetPrimaryRootWindow(),
176 new WindowTypeLauncher, 170 gfx::Rect(120, 150, 300, 410));
177 Shell::GetPrimaryRootWindow(),
178 gfx::Rect(120, 150, 300, 410));
179 widget->GetNativeView()->SetName("WindowTypeLauncher"); 171 widget->GetNativeView()->SetName("WindowTypeLauncher");
180 ::wm::SetShadowType(widget->GetNativeView(), ::wm::SHADOW_TYPE_RECTANGULAR); 172 ::wm::SetShadowType(widget->GetNativeView(), ::wm::SHADOW_TYPE_RECTANGULAR);
181 widget->Show(); 173 widget->Show();
182 } 174 }
183 175
184 WindowTypeLauncher::WindowTypeLauncher() 176 WindowTypeLauncher::WindowTypeLauncher()
185 : create_button_(new views::LabelButton( 177 : create_button_(
186 this, base::ASCIIToUTF16("Create Window"))), 178 new views::LabelButton(this, base::ASCIIToUTF16("Create Window"))),
187 panel_button_(new views::LabelButton( 179 panel_button_(
188 this, base::ASCIIToUTF16("Create Panel"))), 180 new views::LabelButton(this, base::ASCIIToUTF16("Create Panel"))),
189 create_nonresizable_button_(new views::LabelButton( 181 create_nonresizable_button_(new views::LabelButton(
190 this, base::ASCIIToUTF16("Create Non-Resizable Window"))), 182 this,
191 bubble_button_(new views::LabelButton( 183 base::ASCIIToUTF16("Create Non-Resizable Window"))),
192 this, base::ASCIIToUTF16("Create Pointy Bubble"))), 184 bubble_button_(
193 lock_button_(new views::LabelButton( 185 new views::LabelButton(this,
194 this, base::ASCIIToUTF16("Lock Screen"))), 186 base::ASCIIToUTF16("Create Pointy Bubble"))),
195 widgets_button_(new views::LabelButton( 187 lock_button_(
196 this, base::ASCIIToUTF16("Show Example Widgets"))), 188 new views::LabelButton(this, base::ASCIIToUTF16("Lock Screen"))),
189 widgets_button_(
190 new views::LabelButton(this,
191 base::ASCIIToUTF16("Show Example Widgets"))),
197 system_modal_button_(new views::LabelButton( 192 system_modal_button_(new views::LabelButton(
198 this, base::ASCIIToUTF16("Open System Modal Window"))), 193 this,
194 base::ASCIIToUTF16("Open System Modal Window"))),
199 window_modal_button_(new views::LabelButton( 195 window_modal_button_(new views::LabelButton(
200 this, base::ASCIIToUTF16("Open Window Modal Window"))), 196 this,
197 base::ASCIIToUTF16("Open Window Modal Window"))),
201 child_modal_button_(new views::LabelButton( 198 child_modal_button_(new views::LabelButton(
202 this, base::ASCIIToUTF16("Open Child Modal Window"))), 199 this,
200 base::ASCIIToUTF16("Open Child Modal Window"))),
203 transient_button_(new views::LabelButton( 201 transient_button_(new views::LabelButton(
204 this, base::ASCIIToUTF16("Open Non-Modal Transient Window"))), 202 this,
203 base::ASCIIToUTF16("Open Non-Modal Transient Window"))),
205 examples_button_(new views::LabelButton( 204 examples_button_(new views::LabelButton(
206 this, base::ASCIIToUTF16("Open Views Examples Window"))), 205 this,
207 show_hide_window_button_(new views::LabelButton( 206 base::ASCIIToUTF16("Open Views Examples Window"))),
208 this, base::ASCIIToUTF16("Show/Hide a Window"))), 207 show_hide_window_button_(
208 new views::LabelButton(this,
209 base::ASCIIToUTF16("Show/Hide a Window"))),
209 show_web_notification_(new views::LabelButton( 210 show_web_notification_(new views::LabelButton(
210 this, base::ASCIIToUTF16("Show a web/app notification"))) { 211 this,
212 base::ASCIIToUTF16("Show a web/app notification"))) {
211 create_button_->SetStyle(views::Button::STYLE_BUTTON); 213 create_button_->SetStyle(views::Button::STYLE_BUTTON);
212 panel_button_->SetStyle(views::Button::STYLE_BUTTON); 214 panel_button_->SetStyle(views::Button::STYLE_BUTTON);
213 create_nonresizable_button_->SetStyle(views::Button::STYLE_BUTTON); 215 create_nonresizable_button_->SetStyle(views::Button::STYLE_BUTTON);
214 bubble_button_->SetStyle(views::Button::STYLE_BUTTON); 216 bubble_button_->SetStyle(views::Button::STYLE_BUTTON);
215 lock_button_->SetStyle(views::Button::STYLE_BUTTON); 217 lock_button_->SetStyle(views::Button::STYLE_BUTTON);
216 widgets_button_->SetStyle(views::Button::STYLE_BUTTON); 218 widgets_button_->SetStyle(views::Button::STYLE_BUTTON);
217 system_modal_button_->SetStyle(views::Button::STYLE_BUTTON); 219 system_modal_button_->SetStyle(views::Button::STYLE_BUTTON);
218 window_modal_button_->SetStyle(views::Button::STYLE_BUTTON); 220 window_modal_button_->SetStyle(views::Button::STYLE_BUTTON);
219 child_modal_button_->SetStyle(views::Button::STYLE_BUTTON); 221 child_modal_button_->SetStyle(views::Button::STYLE_BUTTON);
220 transient_button_->SetStyle(views::Button::STYLE_BUTTON); 222 transient_button_->SetStyle(views::Button::STYLE_BUTTON);
221 examples_button_->SetStyle(views::Button::STYLE_BUTTON); 223 examples_button_->SetStyle(views::Button::STYLE_BUTTON);
222 show_hide_window_button_->SetStyle(views::Button::STYLE_BUTTON); 224 show_hide_window_button_->SetStyle(views::Button::STYLE_BUTTON);
223 show_web_notification_->SetStyle(views::Button::STYLE_BUTTON); 225 show_web_notification_->SetStyle(views::Button::STYLE_BUTTON);
224 226
225 views::GridLayout* layout = new views::GridLayout(this); 227 views::GridLayout* layout = new views::GridLayout(this);
226 layout->SetInsets(5, 5, 5, 5); 228 layout->SetInsets(5, 5, 5, 5);
227 SetLayoutManager(layout); 229 SetLayoutManager(layout);
228 views::ColumnSet* column_set = layout->AddColumnSet(0); 230 views::ColumnSet* column_set = layout->AddColumnSet(0);
229 column_set->AddColumn(views::GridLayout::LEADING, 231 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
230 views::GridLayout::CENTER, 232 0, views::GridLayout::USE_PREF, 0, 0);
231 0,
232 views::GridLayout::USE_PREF,
233 0,
234 0);
235 AddViewToLayout(layout, create_button_); 233 AddViewToLayout(layout, create_button_);
236 AddViewToLayout(layout, panel_button_); 234 AddViewToLayout(layout, panel_button_);
237 AddViewToLayout(layout, create_nonresizable_button_); 235 AddViewToLayout(layout, create_nonresizable_button_);
238 AddViewToLayout(layout, bubble_button_); 236 AddViewToLayout(layout, bubble_button_);
239 AddViewToLayout(layout, lock_button_); 237 AddViewToLayout(layout, lock_button_);
240 AddViewToLayout(layout, widgets_button_); 238 AddViewToLayout(layout, widgets_button_);
241 AddViewToLayout(layout, system_modal_button_); 239 AddViewToLayout(layout, system_modal_button_);
242 AddViewToLayout(layout, window_modal_button_); 240 AddViewToLayout(layout, window_modal_button_);
243 AddViewToLayout(layout, child_modal_button_); 241 AddViewToLayout(layout, child_modal_button_);
244 AddViewToLayout(layout, transient_button_); 242 AddViewToLayout(layout, transient_button_);
245 AddViewToLayout(layout, examples_button_); 243 AddViewToLayout(layout, examples_button_);
246 AddViewToLayout(layout, show_hide_window_button_); 244 AddViewToLayout(layout, show_hide_window_button_);
247 AddViewToLayout(layout, show_web_notification_); 245 AddViewToLayout(layout, show_web_notification_);
248 set_context_menu_controller(this); 246 set_context_menu_controller(this);
249 } 247 }
250 248
251 WindowTypeLauncher::~WindowTypeLauncher() { 249 WindowTypeLauncher::~WindowTypeLauncher() {}
252 }
253 250
254 void WindowTypeLauncher::OnPaint(gfx::Canvas* canvas) { 251 void WindowTypeLauncher::OnPaint(gfx::Canvas* canvas) {
255 canvas->FillRect(GetLocalBounds(), SK_ColorWHITE); 252 canvas->FillRect(GetLocalBounds(), SK_ColorWHITE);
256 } 253 }
257 254
258 bool WindowTypeLauncher::OnMousePressed(const ui::MouseEvent& event) { 255 bool WindowTypeLauncher::OnMousePressed(const ui::MouseEvent& event) {
259 // Overridden so we get OnMouseReleased and can show the context menu. 256 // Overridden so we get OnMouseReleased and can show the context menu.
260 return true; 257 return true;
261 } 258 }
262 259
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 default: 342 default:
346 break; 343 break;
347 } 344 }
348 } 345 }
349 346
350 void WindowTypeLauncher::ShowContextMenuForView( 347 void WindowTypeLauncher::ShowContextMenuForView(
351 views::View* source, 348 views::View* source,
352 const gfx::Point& point, 349 const gfx::Point& point,
353 ui::MenuSourceType source_type) { 350 ui::MenuSourceType source_type) {
354 MenuItemView* root = new MenuItemView(this); 351 MenuItemView* root = new MenuItemView(this);
355 root->AppendMenuItem(COMMAND_NEW_WINDOW, 352 root->AppendMenuItem(COMMAND_NEW_WINDOW, base::ASCIIToUTF16("New Window"),
356 base::ASCIIToUTF16("New Window"),
357 MenuItemView::NORMAL); 353 MenuItemView::NORMAL);
358 root->AppendMenuItem(COMMAND_TOGGLE_FULLSCREEN, 354 root->AppendMenuItem(COMMAND_TOGGLE_FULLSCREEN,
359 base::ASCIIToUTF16("Toggle FullScreen"), 355 base::ASCIIToUTF16("Toggle FullScreen"),
360 MenuItemView::NORMAL); 356 MenuItemView::NORMAL);
361 // MenuRunner takes ownership of root. 357 // MenuRunner takes ownership of root.
362 menu_runner_.reset(new MenuRunner( 358 menu_runner_.reset(new MenuRunner(
363 root, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); 359 root, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
364 if (menu_runner_->RunMenuAt(GetWidget(), 360 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(point, gfx::Size()),
365 NULL,
366 gfx::Rect(point, gfx::Size()),
367 views::MENU_ANCHOR_TOPLEFT, 361 views::MENU_ANCHOR_TOPLEFT,
368 source_type) == MenuRunner::MENU_DELETED) { 362 source_type) == MenuRunner::MENU_DELETED) {
369 return; 363 return;
370 } 364 }
371 } 365 }
372 366
373 } // namespace shell 367 } // namespace shell
374 } // namespace ash 368 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell/widgets.cc ('k') | ash/shell/window_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698