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

Side by Side Diff: components/exo/shell_surface.cc

Issue 2900783003: Handle app custom icon via aura::Window property. (Closed)
Patch Set: nits rebase Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/shell_surface.h" 5 #include "components/exo/shell_surface.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/frame/custom_frame_view_ash.h" 9 #include "ash/frame/custom_frame_view_ash.h"
10 #include "ash/public/cpp/shelf_types.h" 10 #include "ash/public/cpp/shelf_types.h"
(...skipping 24 matching lines...) Expand all
35 #include "ui/display/screen.h" 35 #include "ui/display/screen.h"
36 #include "ui/gfx/path.h" 36 #include "ui/gfx/path.h"
37 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
38 #include "ui/wm/core/coordinate_conversion.h" 38 #include "ui/wm/core/coordinate_conversion.h"
39 #include "ui/wm/core/shadow.h" 39 #include "ui/wm/core/shadow.h"
40 #include "ui/wm/core/shadow_controller.h" 40 #include "ui/wm/core/shadow_controller.h"
41 #include "ui/wm/core/shadow_types.h" 41 #include "ui/wm/core/shadow_types.h"
42 #include "ui/wm/core/window_animations.h" 42 #include "ui/wm/core/window_animations.h"
43 #include "ui/wm/core/window_util.h" 43 #include "ui/wm/core/window_util.h"
44 44
45 DECLARE_UI_CLASS_PROPERTY_TYPE(exo::ShellSurface*)
reveman 2017/06/01 18:28:42 Don't add this. Launcher code can get the ShellSur
khmel 2017/06/01 21:55:46 Good point, thanks!
46
45 namespace exo { 47 namespace exo {
46 namespace { 48 namespace {
47 49
48 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) 50 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr)
51 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(ShellSurface*, kThisSurfaceKey, nullptr)
49 52
50 // Application Id set by the client. 53 // Application Id set by the client.
51 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kApplicationIdKey, nullptr); 54 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kApplicationIdKey, nullptr);
52 55
53 // This is a struct for accelerator keys used to close ShellSurfaces. 56 // This is a struct for accelerator keys used to close ShellSurfaces.
54 const struct Accelerator { 57 const struct Accelerator {
55 ui::KeyboardCode keycode; 58 ui::KeyboardCode keycode;
56 int modifiers; 59 int modifiers;
57 } kCloseWindowAccelerators[] = { 60 } kCloseWindowAccelerators[] = {
58 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, 61 {ui::VKEY_W, ui::EF_CONTROL_DOWN},
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 return window->GetProperty(kApplicationIdKey); 527 return window->GetProperty(kApplicationIdKey);
525 } 528 }
526 529
527 void ShellSurface::SetApplicationId(const std::string& application_id) { 530 void ShellSurface::SetApplicationId(const std::string& application_id) {
528 // Store the value in |application_id_| in case the window does not exist yet. 531 // Store the value in |application_id_| in case the window does not exist yet.
529 application_id_ = application_id; 532 application_id_ = application_id;
530 if (widget_ && widget_->GetNativeWindow()) 533 if (widget_ && widget_->GetNativeWindow())
531 SetApplicationId(widget_->GetNativeWindow(), application_id); 534 SetApplicationId(widget_->GetNativeWindow(), application_id);
532 } 535 }
533 536
537 // static
538 void ShellSurface::SetAppIcon(aura::Window* window,
539 const gfx::ImageSkia& icon) {
540 DCHECK(GetApplicationId(window) && !GetApplicationId(window)->empty());
541 ShellSurface* this_surface = window->GetProperty(kThisSurfaceKey);
542 if (this_surface) {
543 this_surface->icon_ = icon;
544 this_surface->widget_->UpdateWindowIcon();
545 } else {
546 // Support unit test case.
547 window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(icon));
548 }
549 }
550
534 void ShellSurface::Move() { 551 void ShellSurface::Move() {
535 TRACE_EVENT0("exo", "ShellSurface::Move"); 552 TRACE_EVENT0("exo", "ShellSurface::Move");
536 553
537 if (!widget_) 554 if (!widget_)
538 return; 555 return;
539 556
540 switch (bounds_mode_) { 557 switch (bounds_mode_) {
541 case BoundsMode::SHELL: 558 case BoundsMode::SHELL:
542 case BoundsMode::CLIENT: 559 case BoundsMode::CLIENT:
543 AttemptToStartDrag(HTCAPTION); 560 AttemptToStartDrag(HTCAPTION);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 } 829 }
813 830
814 bool ShellSurface::CanMinimize() const { 831 bool ShellSurface::CanMinimize() const {
815 return can_minimize_; 832 return can_minimize_;
816 } 833 }
817 834
818 base::string16 ShellSurface::GetWindowTitle() const { 835 base::string16 ShellSurface::GetWindowTitle() const {
819 return title_; 836 return title_;
820 } 837 }
821 838
839 gfx::ImageSkia ShellSurface::GetWindowIcon() {
840 return icon_;
841 }
842
822 void ShellSurface::SaveWindowPlacement(const gfx::Rect& bounds, 843 void ShellSurface::SaveWindowPlacement(const gfx::Rect& bounds,
823 ui::WindowShowState show_state) { 844 ui::WindowShowState show_state) {
824 if (bounds_mode_ != BoundsMode::CLIENT) 845 if (bounds_mode_ != BoundsMode::CLIENT)
825 WidgetDelegate::SaveWindowPlacement(bounds, show_state); 846 WidgetDelegate::SaveWindowPlacement(bounds, show_state);
826 } 847 }
827 848
828 bool ShellSurface::GetSavedWindowPlacement( 849 bool ShellSurface::GetSavedWindowPlacement(
829 const views::Widget* widget, 850 const views::Widget* widget,
830 gfx::Rect* bounds, 851 gfx::Rect* bounds,
831 ui::WindowShowState* show_state) const { 852 ui::WindowShowState* show_state) const {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 widget_->Init(params); 1170 widget_->Init(params);
1150 1171
1151 aura::Window* window = widget_->GetNativeWindow(); 1172 aura::Window* window = widget_->GetNativeWindow();
1152 window->SetName("ExoShellSurface"); 1173 window->SetName("ExoShellSurface");
1153 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey, 1174 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey,
1154 false); 1175 false);
1155 window->AddChild(surface_->window()); 1176 window->AddChild(surface_->window());
1156 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); 1177 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_)));
1157 SetApplicationId(window, application_id_); 1178 SetApplicationId(window, application_id_);
1158 SetMainSurface(window, surface_); 1179 SetMainSurface(window, surface_);
1180 window->SetProperty(kThisSurfaceKey, this);
1159 1181
1160 // Start tracking changes to window bounds and window state. 1182 // Start tracking changes to window bounds and window state.
1161 window->AddObserver(this); 1183 window->AddObserver(this);
1162 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); 1184 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window);
1163 window_state->AddObserver(this); 1185 window_state->AddObserver(this);
1164 1186
1165 // Allow the client to request bounds that do not fill the entire work area 1187 // Allow the client to request bounds that do not fill the entire work area
1166 // when maximized, or the entire display when fullscreen. 1188 // when maximized, or the entire display when fullscreen.
1167 window_state->set_allow_set_bounds_direct(bounds_mode_ == BoundsMode::CLIENT); 1189 window_state->set_allow_set_bounds_direct(bounds_mode_ == BoundsMode::CLIENT);
1168 1190
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 gfx::Point ShellSurface::GetMouseLocation() const { 1690 gfx::Point ShellSurface::GetMouseLocation() const {
1669 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); 1691 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow();
1670 gfx::Point location = 1692 gfx::Point location =
1671 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); 1693 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
1672 aura::Window::ConvertPointToTarget( 1694 aura::Window::ConvertPointToTarget(
1673 root_window, widget_->GetNativeWindow()->parent(), &location); 1695 root_window, widget_->GetNativeWindow()->parent(), &location);
1674 return location; 1696 return location;
1675 } 1697 }
1676 1698
1677 } // namespace exo 1699 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698