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

Side by Side Diff: ash/common/wm/window_cycle_list.cc

Issue 2699033002: Replace WmWindowObserver with aura::WindowObserver. (Closed)
Patch Set: Check for null images in ShelfWindowWatcher. Created 3 years, 10 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/common/wm/window_cycle_list.h ('k') | ash/common/wm/window_dimmer.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/common/wm/window_cycle_list.h" 5 #include "ash/common/wm/window_cycle_list.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "ash/common/wm/mru_window_tracker.h" 10 #include "ash/common/wm/mru_window_tracker.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 private: 55 private:
56 std::unique_ptr<views::Painter> painter_; 56 std::unique_ptr<views::Painter> painter_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(LayerFillBackgroundPainter); 58 DISALLOW_COPY_AND_ASSIGN(LayerFillBackgroundPainter);
59 }; 59 };
60 60
61 } // namespace 61 } // namespace
62 62
63 // This view represents a single WmWindow by displaying a title and a thumbnail 63 // This view represents a single WmWindow by displaying a title and a thumbnail
64 // of the window's contents. 64 // of the window's contents.
65 class WindowPreviewView : public views::View, public WmWindowObserver { 65 class WindowPreviewView : public views::View, public aura::WindowObserver {
66 public: 66 public:
67 explicit WindowPreviewView(WmWindow* window) 67 explicit WindowPreviewView(WmWindow* window)
68 : window_title_(new views::Label), 68 : window_title_(new views::Label),
69 preview_background_(new views::View), 69 preview_background_(new views::View),
70 mirror_view_(window->CreateViewWithRecreatedLayers().release()), 70 mirror_view_(window->CreateViewWithRecreatedLayers().release()),
71 window_observer_(this) { 71 window_observer_(this) {
72 window_observer_.Add(window); 72 window_observer_.Add(window->aura_window());
73 window_title_->SetText(window->GetTitle()); 73 window_title_->SetText(window->GetTitle());
74 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 74 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
75 window_title_->SetEnabledColor(SK_ColorWHITE); 75 window_title_->SetEnabledColor(SK_ColorWHITE);
76 window_title_->SetAutoColorReadabilityEnabled(false); 76 window_title_->SetAutoColorReadabilityEnabled(false);
77 // Background is not fully opaque, so subpixel rendering won't look good. 77 // Background is not fully opaque, so subpixel rendering won't look good.
78 window_title_->SetSubpixelRenderingEnabled(false); 78 window_title_->SetSubpixelRenderingEnabled(false);
79 // The base font is 12pt (for English) so this comes out to 14pt. 79 // The base font is 12pt (for English) so this comes out to 14pt.
80 const int kLabelSizeDelta = 2; 80 const int kLabelSizeDelta = 2;
81 window_title_->SetFontList( 81 window_title_->SetFontList(
82 window_title_->font_list().DeriveWithSizeDelta(kLabelSizeDelta)); 82 window_title_->font_list().DeriveWithSizeDelta(kLabelSizeDelta));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 preview_background_->SetVisible(true); 128 preview_background_->SetVisible(true);
129 preview_area_bounds.ClampToCenteredSize(mirror_view_->size()); 129 preview_area_bounds.ClampToCenteredSize(mirror_view_->size());
130 mirror_view_->SetPosition(preview_area_bounds.origin()); 130 mirror_view_->SetPosition(preview_area_bounds.origin());
131 } 131 }
132 132
133 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { 133 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
134 node_data->role = ui::AX_ROLE_WINDOW; 134 node_data->role = ui::AX_ROLE_WINDOW;
135 node_data->SetName(window_title_->text()); 135 node_data->SetName(window_title_->text());
136 } 136 }
137 137
138 // WmWindowObserver: 138 // aura::WindowObserver:
139 void OnWindowDestroying(WmWindow* window) override { 139 void OnWindowDestroying(aura::Window* window) override {
140 window_observer_.Remove(window); 140 window_observer_.Remove(window);
141 } 141 }
142 142
143 void OnWindowTitleChanged(WmWindow* window) override { 143 void OnWindowTitleChanged(aura::Window* window) override {
144 window_title_->SetText(window->GetTitle()); 144 window_title_->SetText(window->GetTitle());
145 } 145 }
146 146
147 private: 147 private:
148 // The maximum width of a window preview. 148 // The maximum width of a window preview.
149 static const int kMaxPreviewWidth = 512; 149 static const int kMaxPreviewWidth = 512;
150 // All previews are the same height (this is achieved via a combination of 150 // All previews are the same height (this is achieved via a combination of
151 // scaling and padding). 151 // scaling and padding).
152 static const int kFixedPreviewHeight = 256; 152 static const int kFixedPreviewHeight = 256;
153 153
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 194
195 // Displays the title of the window above the preview. 195 // Displays the title of the window above the preview.
196 views::Label* window_title_; 196 views::Label* window_title_;
197 // When visible, shows a darkened background area behind |mirror_view_| 197 // When visible, shows a darkened background area behind |mirror_view_|
198 // (effectively padding the preview to fit the desired bounds). 198 // (effectively padding the preview to fit the desired bounds).
199 views::View* preview_background_; 199 views::View* preview_background_;
200 // The view that actually renders a thumbnail version of the window. 200 // The view that actually renders a thumbnail version of the window.
201 views::View* mirror_view_; 201 views::View* mirror_view_;
202 202
203 ScopedObserver<WmWindow, WmWindowObserver> window_observer_; 203 ScopedObserver<aura::Window, aura::WindowObserver> window_observer_;
204 204
205 DISALLOW_COPY_AND_ASSIGN(WindowPreviewView); 205 DISALLOW_COPY_AND_ASSIGN(WindowPreviewView);
206 }; 206 };
207 207
208 // A view that shows a collection of windows the user can tab through. 208 // A view that shows a collection of windows the user can tab through.
209 class WindowCycleView : public views::WidgetDelegateView { 209 class WindowCycleView : public views::WidgetDelegateView {
210 public: 210 public:
211 explicit WindowCycleView(const WindowCycleList::WindowList& windows) 211 explicit WindowCycleView(const WindowCycleList::WindowList& windows)
212 : mirror_container_(new views::View()), 212 : mirror_container_(new views::View()),
213 highlight_view_(new views::View()), 213 highlight_view_(new views::View()),
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 DISALLOW_COPY_AND_ASSIGN(WindowCycleView); 379 DISALLOW_COPY_AND_ASSIGN(WindowCycleView);
380 }; 380 };
381 381
382 WindowCycleList::WindowCycleList(const WindowList& windows) 382 WindowCycleList::WindowCycleList(const WindowList& windows)
383 : windows_(windows), 383 : windows_(windows),
384 screen_observer_(this) { 384 screen_observer_(this) {
385 if (!ShouldShowUi()) 385 if (!ShouldShowUi())
386 WmShell::Get()->mru_window_tracker()->SetIgnoreActivations(true); 386 WmShell::Get()->mru_window_tracker()->SetIgnoreActivations(true);
387 387
388 for (WmWindow* window : windows_) 388 for (WmWindow* window : windows_)
389 window->AddObserver(this); 389 window->aura_window()->AddObserver(this);
390 390
391 if (ShouldShowUi()) { 391 if (ShouldShowUi()) {
392 if (g_disable_initial_delay) { 392 if (g_disable_initial_delay) {
393 InitWindowCycleView(); 393 InitWindowCycleView();
394 } else { 394 } else {
395 show_ui_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(150), 395 show_ui_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(150),
396 this, &WindowCycleList::InitWindowCycleView); 396 this, &WindowCycleList::InitWindowCycleView);
397 } 397 }
398 } 398 }
399 } 399 }
400 400
401 WindowCycleList::~WindowCycleList() { 401 WindowCycleList::~WindowCycleList() {
402 if (!ShouldShowUi()) 402 if (!ShouldShowUi())
403 WmShell::Get()->mru_window_tracker()->SetIgnoreActivations(false); 403 WmShell::Get()->mru_window_tracker()->SetIgnoreActivations(false);
404 404
405 for (WmWindow* window : windows_) 405 for (WmWindow* window : windows_)
406 window->RemoveObserver(this); 406 window->aura_window()->RemoveObserver(this);
407 407
408 if (!windows_.empty() && user_did_accept_) { 408 if (!windows_.empty() && user_did_accept_) {
409 WmWindow* target_window = windows_[current_index_]; 409 WmWindow* target_window = windows_[current_index_];
410 target_window->Show(); 410 target_window->Show();
411 target_window->GetWindowState()->Activate(); 411 target_window->GetWindowState()->Activate();
412 } 412 }
413 413
414 if (cycle_ui_widget_) 414 if (cycle_ui_widget_)
415 cycle_ui_widget_->Close(); 415 cycle_ui_widget_->Close();
416 416
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if (cycle_view_) 460 if (cycle_view_)
461 cycle_view_->SetTargetWindow(windows_[current_index_]); 461 cycle_view_->SetTargetWindow(windows_[current_index_]);
462 } 462 }
463 } 463 }
464 464
465 // static 465 // static
466 void WindowCycleList::DisableInitialDelayForTesting() { 466 void WindowCycleList::DisableInitialDelayForTesting() {
467 g_disable_initial_delay = true; 467 g_disable_initial_delay = true;
468 } 468 }
469 469
470 void WindowCycleList::OnWindowDestroying(WmWindow* window) { 470 void WindowCycleList::OnWindowDestroying(aura::Window* window) {
471 window->RemoveObserver(this); 471 window->RemoveObserver(this);
472 472
473 WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window); 473 WindowList::iterator i =
474 std::find(windows_.begin(), windows_.end(), WmWindow::Get(window));
474 // TODO(oshima): Change this back to DCHECK once crbug.com/483491 is fixed. 475 // TODO(oshima): Change this back to DCHECK once crbug.com/483491 is fixed.
475 CHECK(i != windows_.end()); 476 CHECK(i != windows_.end());
476 int removed_index = static_cast<int>(i - windows_.begin()); 477 int removed_index = static_cast<int>(i - windows_.begin());
477 windows_.erase(i); 478 windows_.erase(i);
478 if (current_index_ > removed_index || 479 if (current_index_ > removed_index ||
479 current_index_ == static_cast<int>(windows_.size())) { 480 current_index_ == static_cast<int>(windows_.size())) {
480 current_index_--; 481 current_index_--;
481 } 482 }
482 483
483 if (cycle_view_) { 484 if (cycle_view_) {
484 WmWindow* new_target_window = 485 WmWindow* new_target_window =
485 windows_.empty() ? nullptr : windows_[current_index_]; 486 windows_.empty() ? nullptr : windows_[current_index_];
486 cycle_view_->HandleWindowDestruction(window, new_target_window); 487 cycle_view_->HandleWindowDestruction(WmWindow::Get(window),
488 new_target_window);
487 if (windows_.empty()) { 489 if (windows_.empty()) {
488 // This deletes us. 490 // This deletes us.
489 WmShell::Get()->window_cycle_controller()->CancelCycling(); 491 WmShell::Get()->window_cycle_controller()->CancelCycling();
490 return; 492 return;
491 } 493 }
492 } 494 }
493 } 495 }
494 496
495 void WindowCycleList::OnDisplayAdded(const display::Display& new_display) {} 497 void WindowCycleList::OnDisplayAdded(const display::Display& new_display) {}
496 498
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 widget_rect.set_height(widget_height); 542 widget_rect.set_height(widget_height);
541 params.bounds = widget_rect; 543 params.bounds = widget_rect;
542 widget->Init(params); 544 widget->Init(params);
543 545
544 screen_observer_.Add(display::Screen::GetScreen()); 546 screen_observer_.Add(display::Screen::GetScreen());
545 widget->Show(); 547 widget->Show();
546 cycle_ui_widget_ = widget; 548 cycle_ui_widget_ = widget;
547 } 549 }
548 550
549 } // namespace ash 551 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/window_cycle_list.h ('k') | ash/common/wm/window_dimmer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698