osr_view_proxy.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/osr/osr_view_proxy.h"
  5. namespace electron {
  6. OffscreenViewProxy::OffscreenViewProxy(views::View* view) : view_(view) {
  7. view_bitmap_.reset(new SkBitmap);
  8. }
  9. OffscreenViewProxy::~OffscreenViewProxy() {
  10. if (observer_) {
  11. observer_->ProxyViewDestroyed(this);
  12. }
  13. }
  14. void OffscreenViewProxy::SetObserver(OffscreenViewProxyObserver* observer) {
  15. if (observer_) {
  16. observer_->ProxyViewDestroyed(this);
  17. }
  18. observer_ = observer;
  19. }
  20. void OffscreenViewProxy::RemoveObserver() {
  21. observer_ = nullptr;
  22. }
  23. const SkBitmap* OffscreenViewProxy::GetBitmap() const {
  24. return view_bitmap_.get();
  25. }
  26. void OffscreenViewProxy::SetBitmap(const SkBitmap& bitmap) {
  27. if (view_bounds_.width() == bitmap.width() &&
  28. view_bounds_.height() == bitmap.height() && observer_) {
  29. view_bitmap_.reset(new SkBitmap(bitmap));
  30. observer_->OnProxyViewPaint(view_bounds_);
  31. }
  32. }
  33. const gfx::Rect& OffscreenViewProxy::GetBounds() {
  34. return view_bounds_;
  35. }
  36. void OffscreenViewProxy::SetBounds(const gfx::Rect& bounds) {
  37. view_bounds_ = bounds;
  38. }
  39. void OffscreenViewProxy::OnEvent(ui::Event* event) {
  40. if (view_) {
  41. view_->OnEvent(event);
  42. }
  43. }
  44. } // namespace electron