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

Side by Side Diff: chrome/browser/ui/ash/launcher/settings_window_observer.cc

Issue 2578893003: Converts chrome to aura-mus (Closed)
Patch Set: merge again Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/ash/launcher/settings_window_observer.h" 5 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h"
6 6
7 #include "ash/common/shelf/shelf_item_types.h" 7 #include "ash/common/shelf/shelf_item_types.h"
8 #include "ash/resources/grit/ash_resources.h" 8 #include "ash/resources/grit/ash_resources.h"
9 #include "ash/wm/window_properties.h" 9 #include "ash/wm/window_properties.h"
10 #include "chrome/browser/ui/ash/ash_util.h" 10 #include "chrome/browser/ui/ash/ash_util.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/settings_window_manager.h" 13 #include "chrome/browser/ui/settings_window_manager.h"
14 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
15 #include "services/ui/public/cpp/property_type_converters.h"
16 #include "services/ui/public/cpp/window.h"
17 #include "services/ui/public/cpp/window_property.h"
18 #include "services/ui/public/interfaces/window_manager.mojom.h" 15 #include "services/ui/public/interfaces/window_manager.mojom.h"
19 #include "ui/aura/client/aura_constants.h" 16 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/mus/mus_util.h"
21 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
22 #include "ui/aura/window_property.h" 18 #include "ui/aura/window_property.h"
23 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
26 22
27 namespace { 23 namespace {
28 24
29 // This class is only used in classic ash to rename the Settings window. 25 // This class is only used in classic ash to rename the Settings window.
30 class AuraWindowSettingsTitleTracker : public aura::WindowTracker { 26 class AuraWindowSettingsTitleTracker : public aura::WindowTracker {
31 public: 27 public:
32 AuraWindowSettingsTitleTracker() {} 28 AuraWindowSettingsTitleTracker() {}
33 ~AuraWindowSettingsTitleTracker() override {} 29 ~AuraWindowSettingsTitleTracker() override {}
34 30
35 // aura::WindowTracker: 31 // aura::WindowTracker:
36 void OnWindowTitleChanged(aura::Window* window) override { 32 void OnWindowTitleChanged(aura::Window* window) override {
37 // Name the window "Settings" instead of "Google Chrome - Settings". 33 // Name the window "Settings" instead of "Google Chrome - Settings".
38 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); 34 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
39 } 35 }
40 36
41 private: 37 private:
42 DISALLOW_COPY_AND_ASSIGN(AuraWindowSettingsTitleTracker); 38 DISALLOW_COPY_AND_ASSIGN(AuraWindowSettingsTitleTracker);
43 }; 39 };
44 40
45 // This class is only used in mash (mus+ash) to rename the Settings window.
46 class UiWindowSettingsTitleTracker : public ui::WindowTracker {
47 public:
48 UiWindowSettingsTitleTracker() {}
49 ~UiWindowSettingsTitleTracker() override {}
50
51 // ui::WindowTracker:
52 void OnWindowSharedPropertyChanged(
53 ui::Window* window,
54 const std::string& name,
55 const std::vector<uint8_t>* old_data,
56 const std::vector<uint8_t>* new_data) override {
57 if (name == ui::mojom::WindowManager::kWindowTitle_Property) {
58 // Name the window "Settings" instead of "Google Chrome - Settings".
59 window->SetSharedProperty<base::string16>(
60 ui::mojom::WindowManager::kWindowTitle_Property,
61 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
62 }
63 }
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(UiWindowSettingsTitleTracker);
67 };
68
69 } // namespace 41 } // namespace
70 42
71 SettingsWindowObserver::SettingsWindowObserver() { 43 SettingsWindowObserver::SettingsWindowObserver() {
72 if (chrome::IsRunningInMash()) 44 aura_window_tracker_ = base::MakeUnique<AuraWindowSettingsTitleTracker>();
73 ui_window_tracker_.reset(new UiWindowSettingsTitleTracker);
74 else
75 aura_window_tracker_.reset(new AuraWindowSettingsTitleTracker);
76 chrome::SettingsWindowManager::GetInstance()->AddObserver(this); 45 chrome::SettingsWindowManager::GetInstance()->AddObserver(this);
77 } 46 }
78 47
79 SettingsWindowObserver::~SettingsWindowObserver() { 48 SettingsWindowObserver::~SettingsWindowObserver() {
80 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(this); 49 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(this);
81 } 50 }
82 51
83 void SettingsWindowObserver::OnNewSettingsWindow(Browser* settings_browser) { 52 void SettingsWindowObserver::OnNewSettingsWindow(Browser* settings_browser) {
84 aura::Window* window = settings_browser->window()->GetNativeWindow(); 53 aura::Window* window = settings_browser->window()->GetNativeWindow();
85 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); 54 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE));
86 window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_DIALOG); 55 window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_DIALOG);
87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 56 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
88 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_ASH_SHELF_ICON_SETTINGS); 57 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_ASH_SHELF_ICON_SETTINGS);
89 // The new gfx::ImageSkia instance is owned by the window itself. 58 // The new gfx::ImageSkia instance is owned by the window itself.
90 window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(*icon)); 59 window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(*icon));
91 60 aura_window_tracker_->Add(window);
92 if (chrome::IsRunningInMash())
93 ui_window_tracker_->Add(aura::GetMusWindow(window));
94 else
95 aura_window_tracker_->Add(window);
96 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698