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