forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stub in holding space support for dynamic images.
This is the first step in supporting dynamic images for holding space as is needed due to the fact that file thumbnails are loaded async. The next CL will wire the new `HoldingSpaceImage` class up to the existing but currently unused `HoldingSpaceThumbnailLoader`. Bug: 1113772 Change-Id: I5ffc660d5eb3462c247a530f61811c40fcb9b550 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387264 Commit-Queue: David Black <dmblack@google.com> Reviewed-by: Xiyuan Slow <xiyuan@chromium.org> Reviewed-by: Alex Newcomer <newcomer@chromium.org> Cr-Commit-Position: refs/heads/master@{#803737}
- Loading branch information
David Black
authored and
Commit Bot
committed
Sep 2, 2020
1 parent
677ab16
commit c06d590
Showing
24 changed files
with
289 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/public/cpp/holding_space/holding_space_image.h" | ||
|
||
#include <memory> | ||
|
||
#include "ui/gfx/image/image_skia_source.h" | ||
#include "ui/gfx/skia_util.h" | ||
|
||
namespace ash { | ||
|
||
// HoldingSpaceImage::ImageSkiaSource ------------------------------------------ | ||
|
||
class HoldingSpaceImage::ImageSkiaSource : public gfx::ImageSkiaSource { | ||
public: | ||
explicit ImageSkiaSource(const gfx::ImageSkia& placeholder) | ||
: placeholder_(placeholder) {} | ||
ImageSkiaSource(const ImageSkiaSource&) = delete; | ||
ImageSkiaSource& operator=(const ImageSkiaSource&) = delete; | ||
~ImageSkiaSource() override = default; | ||
|
||
private: | ||
// gfx::ImageSkiaSource: | ||
gfx::ImageSkiaRep GetImageForScale(float scale) override { | ||
// TODO(dmblack): Retrieve thumbnail and call `NotifyUpdated()` when ready. | ||
return placeholder_.GetRepresentation(scale); | ||
} | ||
|
||
const gfx::ImageSkia placeholder_; | ||
}; | ||
|
||
// HoldingSpaceImage ----------------------------------------------------------- | ||
|
||
HoldingSpaceImage::HoldingSpaceImage(const gfx::ImageSkia& placeholder) | ||
: image_skia_(std::make_unique<ImageSkiaSource>(placeholder), | ||
placeholder.size()) {} | ||
|
||
HoldingSpaceImage::~HoldingSpaceImage() { | ||
NotifyDestroying(); | ||
} | ||
|
||
bool HoldingSpaceImage::operator==(const HoldingSpaceImage& rhs) const { | ||
return gfx::BitmapsAreEqual(*image_skia_.bitmap(), *rhs.image_skia_.bitmap()); | ||
} | ||
|
||
void HoldingSpaceImage::AddObserver(Observer* observer) const { | ||
observers_.AddObserver(observer); | ||
} | ||
|
||
void HoldingSpaceImage::RemoveObserver(Observer* observer) const { | ||
observers_.RemoveObserver(observer); | ||
} | ||
|
||
void HoldingSpaceImage::NotifyDestroying() { | ||
for (auto& observer : observers_) | ||
observer.OnHoldingSpaceImageDestroying(this); | ||
} | ||
|
||
void HoldingSpaceImage::NotifyUpdated(float scale) { | ||
// Force invalidate `image_skia_` for `scale` so that it will request the | ||
// updated `gfx::ImageSkiaRep` at next access. | ||
image_skia_.RemoveRepresentation(scale); | ||
image_skia_.RemoveUnsupportedRepresentationsForScale(scale); | ||
|
||
for (auto& observer : observers_) | ||
observer.OnHoldingSpaceImageUpdated(this); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_IMAGE_H_ | ||
#define ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_IMAGE_H_ | ||
|
||
#include "ash/public/cpp/ash_public_export.h" | ||
#include "base/observer_list.h" | ||
#include "ui/gfx/image/image_skia.h" | ||
|
||
namespace ash { | ||
|
||
// TODO(dmblack): Implement dynamic updating. | ||
// A wrapper around a `gfx::ImageSkia` that supports dynamic updates. When | ||
// updates occur or an instance is being destroyed, observers are notified. | ||
class ASH_PUBLIC_EXPORT HoldingSpaceImage { | ||
public: | ||
// An observer which receives notifications of `HoldingSpaceImage` events. | ||
class Observer : public base::CheckedObserver { | ||
public: | ||
// Invoked when the `HoldingSpaceImage` is updated. UI classes should react | ||
// to this event by invalidating any associated views. | ||
virtual void OnHoldingSpaceImageUpdated(const HoldingSpaceImage*) {} | ||
|
||
// Invoked when the `HoldingSpaceImage` is being destroyed. Any observers | ||
// should react to this event by unregistering from the observer list. | ||
virtual void OnHoldingSpaceImageDestroying(const HoldingSpaceImage*) {} | ||
}; | ||
|
||
explicit HoldingSpaceImage(const gfx::ImageSkia& placeholder); | ||
HoldingSpaceImage(const HoldingSpaceImage&) = delete; | ||
HoldingSpaceImage& operator=(const HoldingSpaceImage&) = delete; | ||
~HoldingSpaceImage(); | ||
|
||
bool operator==(const HoldingSpaceImage& rhs) const; | ||
|
||
// Adds/remove the specified `observer`. | ||
void AddObserver(Observer* observer) const; | ||
void RemoveObserver(Observer* observer) const; | ||
|
||
// Returns the underlying `gfx::ImageSkia`. Note that the image source may be | ||
// dynamically updated, so UI classes should observe and react to updates. | ||
const gfx::ImageSkia& image_skia() const { return image_skia_; } | ||
|
||
private: | ||
class ImageSkiaSource; | ||
|
||
void NotifyDestroying(); | ||
void NotifyUpdated(float scale); | ||
|
||
gfx::ImageSkia image_skia_; | ||
|
||
// Mutable to allow const access from `AddObserver()`/`RemoveObserver()`. | ||
mutable base::ObserverList<HoldingSpaceImage::Observer> observers_; | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_IMAGE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.