Fix Top Chrome Layout with Custom Theme Installed.
With a custom theme installed, the layout for top chrome was incorrect while in material mode.
PlatformStyle::CreateLabelButtonBorder sets insets on borders for material modes, while LabelButtonAssetBorder applies them for normal. However ToolbarButton and WrenchToolbarButton were only adjusting for these when dealing with a system theme.
Furthermore applying a custom theme was caching the current images. When switching the mode between normal and material, the assets were not updating. Custom theme caching has been updated to create a pack for the current MaterialDesignController::Mode. If modes are switched the custom theme will be re-applied but with the correct assets.
TEST=manual testing on device, ExtensionServiceTest
BUG=511329
Review URL: https://codereview.chromium.org/1323583003
Cr-Commit-Position: refs/heads/master@{#350560}
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 7159543..323ef3a 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -34,6 +34,7 @@
#include "extensions/common/extension_set.h"
#include "grit/theme_resources.h"
#include "ui/base/layout.h"
+#include "ui/base/resource/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia.h"
@@ -78,6 +79,11 @@
// ExtensionService::GarbageCollectExtensions() does something similar.
const int kRemoveUnusedThemesStartupDelay = 30;
+// The filename to be used for a cached theme created while material design is
+// enabled.
+const base::FilePath::CharType kThemePackMaterialDesignFilename[] =
+ FILE_PATH_LITERAL("Cached Theme Material Design.pak");
+
SkColor IncreaseLightness(SkColor color, double percent) {
color_utils::HSL result;
color_utils::SkColorToHSL(color, &result);
@@ -536,9 +542,13 @@
bool loaded_pack = false;
- // If we don't have a file pack, we're updating from an old version.
+ // If we don't have a file pack, we're updating from an old version, or the
+ // pack was created for an alternative MaterialDesignController::Mode.
base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
if (path != base::FilePath()) {
+ path = path.Append(ui::MaterialDesignController::IsModeMaterial()
+ ? kThemePackMaterialDesignFilename
+ : chrome::kThemePackFilename);
SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id));
loaded_pack = theme_supplier_.get() != nullptr;
}
@@ -657,12 +667,16 @@
// Write the packed file to disk.
base::FilePath pack_path =
- extension->path().Append(chrome::kThemePackFilename);
+ extension->path().Append(ui::MaterialDesignController::IsModeMaterial()
+ ? kThemePackMaterialDesignFilename
+ : chrome::kThemePackFilename);
service->GetFileTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&WritePackToDiskCallback, pack, pack_path));
- SavePackName(pack_path);
+ // Save only the extension path. The packed file which matches the
+ // MaterialDesignController::Mode will be loaded via LoadThemePrefs().
+ SavePackName(extension->path());
SwapThemeSupplier(pack);
}