| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/arc_app_window.h" | 5 #include "chrome/browser/ui/ash/launcher/arc_app_window.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" | 8 #include "chrome/browser/ui/app_list/arc/arc_app_icon.h" |
| 9 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 9 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 10 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 10 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 owner_(owner) {} | 26 owner_(owner) {} |
| 27 | 27 |
| 28 ArcAppWindow::~ArcAppWindow() { | 28 ArcAppWindow::~ArcAppWindow() { |
| 29 ImageDecoder::Cancel(this); | 29 ImageDecoder::Cancel(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void ArcAppWindow::SetController( | 32 void ArcAppWindow::SetController( |
| 33 ArcAppWindowLauncherItemController* controller) { | 33 ArcAppWindowLauncherItemController* controller) { |
| 34 DCHECK(!controller_ || !controller); | 34 DCHECK(!controller_ || !controller); |
| 35 controller_ = controller; | 35 controller_ = controller; |
| 36 if (controller_) | |
| 37 controller_->UpdateLauncherItem(); | |
| 38 } | 36 } |
| 39 | 37 |
| 40 void ArcAppWindow::SetFullscreenMode(FullScreenMode mode) { | 38 void ArcAppWindow::SetFullscreenMode(FullScreenMode mode) { |
| 41 DCHECK(mode != FullScreenMode::NOT_DEFINED); | 39 DCHECK(mode != FullScreenMode::NOT_DEFINED); |
| 42 fullscreen_mode_ = mode; | 40 fullscreen_mode_ = mode; |
| 43 } | 41 } |
| 44 | 42 |
| 45 void ArcAppWindow::SetDescription( | 43 void ArcAppWindow::SetDescription( |
| 46 const std::string& title, | 44 const std::string& title, |
| 47 const std::vector<uint8_t>& unsafe_icon_data_png) { | 45 const std::vector<uint8_t>& unsafe_icon_data_png) { |
| 48 if (!title.empty()) | 46 if (!title.empty()) |
| 49 GetNativeWindow()->SetTitle(base::UTF8ToUTF16(title)); | 47 GetNativeWindow()->SetTitle(base::UTF8ToUTF16(title)); |
| 50 ImageDecoder::Cancel(this); | 48 ImageDecoder::Cancel(this); |
| 51 if (unsafe_icon_data_png.empty()) { | 49 if (unsafe_icon_data_png.empty()) { |
| 52 ResetIcon(); | 50 SetIcon(gfx::ImageSkia()); |
| 53 return; | 51 return; |
| 54 } | 52 } |
| 55 | 53 |
| 56 if (ArcAppIcon::IsSafeDecodingDisabledForTesting()) { | 54 if (ArcAppIcon::IsSafeDecodingDisabledForTesting()) { |
| 57 SkBitmap bitmap; | 55 SkBitmap bitmap; |
| 58 if (gfx::PNGCodec::Decode(&unsafe_icon_data_png[0], | 56 if (gfx::PNGCodec::Decode(&unsafe_icon_data_png[0], |
| 59 unsafe_icon_data_png.size(), &bitmap)) { | 57 unsafe_icon_data_png.size(), &bitmap)) { |
| 60 OnImageDecoded(bitmap); | 58 OnImageDecoded(bitmap); |
| 61 } else { | 59 } else { |
| 62 OnDecodeImageFailed(); | 60 OnDecodeImageFailed(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 148 |
| 151 bool ArcAppWindow::IsAlwaysOnTop() const { | 149 bool ArcAppWindow::IsAlwaysOnTop() const { |
| 152 NOTREACHED(); | 150 NOTREACHED(); |
| 153 return false; | 151 return false; |
| 154 } | 152 } |
| 155 | 153 |
| 156 void ArcAppWindow::SetAlwaysOnTop(bool always_on_top) { | 154 void ArcAppWindow::SetAlwaysOnTop(bool always_on_top) { |
| 157 NOTREACHED(); | 155 NOTREACHED(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 void ArcAppWindow::ResetIcon() { | 158 void ArcAppWindow::SetIcon(const gfx::ImageSkia& icon) { |
| 161 if (icon_.isNull()) | 159 if (!exo::ShellSurface::GetMainSurface(GetNativeWindow())) |
| 162 return; | 160 return; |
| 163 icon_ = gfx::ImageSkia(); | 161 exo::ShellSurface* shell_surface = static_cast<exo::ShellSurface*>( |
| 164 if (controller_) | 162 widget_->widget_delegate()->GetContentsView()); |
| 165 controller_->UpdateLauncherItem(); | 163 if (!shell_surface) |
| 164 return; |
| 165 shell_surface->SetIcon(icon); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void ArcAppWindow::OnImageDecoded(const SkBitmap& decoded_image) { | 168 void ArcAppWindow::OnImageDecoded(const SkBitmap& decoded_image) { |
| 169 // TODO(khmel): Use aura::Window property http://crbug.com/724292 | 169 SetIcon(gfx::ImageSkiaOperations::CreateResizedImage( |
| 170 icon_ = gfx::ImageSkiaOperations::CreateResizedImage( | |
| 171 gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)), | 170 gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)), |
| 172 skia::ImageOperations::RESIZE_BEST, | 171 skia::ImageOperations::RESIZE_BEST, |
| 173 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, | 172 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, |
| 174 extension_misc::EXTENSION_ICON_SMALL)); | 173 extension_misc::EXTENSION_ICON_SMALL))); |
| 175 if (controller_) | |
| 176 controller_->UpdateLauncherItem(); | |
| 177 } | 174 } |
| OLD | NEW |