OLD | NEW |
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" |
15 #include "services/ui/public/interfaces/window_manager.mojom.h" | 18 #include "services/ui/public/interfaces/window_manager.mojom.h" |
16 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/mus/mus_util.h" |
17 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
18 #include "ui/aura/window_property.h" | 22 #include "ui/aura/window_property.h" |
19 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
22 | 26 |
23 namespace { | 27 namespace { |
24 | 28 |
25 // This class is only used in classic ash to rename the Settings window. | 29 // This class is only used in classic ash to rename the Settings window. |
26 class AuraWindowSettingsTitleTracker : public aura::WindowTracker { | 30 class AuraWindowSettingsTitleTracker : public aura::WindowTracker { |
27 public: | 31 public: |
28 AuraWindowSettingsTitleTracker() {} | 32 AuraWindowSettingsTitleTracker() {} |
29 ~AuraWindowSettingsTitleTracker() override {} | 33 ~AuraWindowSettingsTitleTracker() override {} |
30 | 34 |
31 // aura::WindowTracker: | 35 // aura::WindowTracker: |
32 void OnWindowTitleChanged(aura::Window* window) override { | 36 void OnWindowTitleChanged(aura::Window* window) override { |
33 // Name the window "Settings" instead of "Google Chrome - Settings". | 37 // Name the window "Settings" instead of "Google Chrome - Settings". |
34 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | 38 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
35 } | 39 } |
36 | 40 |
37 private: | 41 private: |
38 DISALLOW_COPY_AND_ASSIGN(AuraWindowSettingsTitleTracker); | 42 DISALLOW_COPY_AND_ASSIGN(AuraWindowSettingsTitleTracker); |
39 }; | 43 }; |
40 | 44 |
| 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 |
41 } // namespace | 69 } // namespace |
42 | 70 |
43 SettingsWindowObserver::SettingsWindowObserver() { | 71 SettingsWindowObserver::SettingsWindowObserver() { |
44 aura_window_tracker_ = base::MakeUnique<AuraWindowSettingsTitleTracker>(); | 72 if (chrome::IsRunningInMash()) |
| 73 ui_window_tracker_.reset(new UiWindowSettingsTitleTracker); |
| 74 else |
| 75 aura_window_tracker_.reset(new AuraWindowSettingsTitleTracker); |
45 chrome::SettingsWindowManager::GetInstance()->AddObserver(this); | 76 chrome::SettingsWindowManager::GetInstance()->AddObserver(this); |
46 } | 77 } |
47 | 78 |
48 SettingsWindowObserver::~SettingsWindowObserver() { | 79 SettingsWindowObserver::~SettingsWindowObserver() { |
49 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(this); | 80 chrome::SettingsWindowManager::GetInstance()->RemoveObserver(this); |
50 } | 81 } |
51 | 82 |
52 void SettingsWindowObserver::OnNewSettingsWindow(Browser* settings_browser) { | 83 void SettingsWindowObserver::OnNewSettingsWindow(Browser* settings_browser) { |
53 aura::Window* window = settings_browser->window()->GetNativeWindow(); | 84 aura::Window* window = settings_browser->window()->GetNativeWindow(); |
54 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | 85 window->SetTitle(l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
55 window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_DIALOG); | 86 window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_DIALOG); |
56 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
57 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_ASH_SHELF_ICON_SETTINGS); | 88 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_ASH_SHELF_ICON_SETTINGS); |
58 // The new gfx::ImageSkia instance is owned by the window itself. | 89 // The new gfx::ImageSkia instance is owned by the window itself. |
59 window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(*icon)); | 90 window->SetProperty(aura::client::kWindowIconKey, new gfx::ImageSkia(*icon)); |
60 aura_window_tracker_->Add(window); | 91 |
| 92 if (chrome::IsRunningInMash()) |
| 93 ui_window_tracker_->Add(aura::GetMusWindow(window)); |
| 94 else |
| 95 aura_window_tracker_->Add(window); |
61 } | 96 } |
OLD | NEW |