Commit 166a9181 authored by mohsen's avatar mohsen Committed by Commit bot

Move ImageWindowDelegate to ui/aura_extra

In order to be able to use it in places other than content (e.g. handles
for unified touch selection controller), ImageWindowDelegate is moved to
a new ui module called aura_extra.

Also, to make it more useful, ImageWindowDelegate can now be customized
by setting background color and image offset.

COLLABORATOR=mfomitchev
BUG=399721

Review URL: https://codereview.chromium.org/880703002

Cr-Commit-Position: refs/heads/master@{#315344}
parent b6e4a35c
......@@ -230,6 +230,7 @@
['use_aura==1', {
'dependencies': [
'../ui/aura/aura.gyp:*',
'../ui/aura_extra/aura_extra.gyp:*',
],
}],
['use_ash==1', {
......@@ -1272,6 +1273,7 @@
'../skia/skia_tests.gyp:skia_unittests',
'../ui/app_list/app_list.gyp:*',
'../ui/aura/aura.gyp:*',
'../ui/aura_extra/aura_extra.gyp:*',
'../ui/base/ui_base_tests.gyp:ui_base_unittests',
'../ui/compositor/compositor.gyp:*',
'../ui/display/display.gyp:display_unittests',
......
......@@ -361,6 +361,7 @@ source_set("browser") {
if (use_aura) {
deps += [
"//ui/aura",
"//ui/aura_extra",
"//ui/strings",
"//ui/wm",
]
......@@ -377,8 +378,6 @@ source_set("browser") {
"renderer_host/web_input_event_aura.h",
"web_contents/aura/gesture_nav_simple.cc",
"web_contents/aura/gesture_nav_simple.h",
"web_contents/aura/image_window_delegate.cc",
"web_contents/aura/image_window_delegate.h",
"web_contents/aura/overscroll_navigation_overlay.cc",
"web_contents/aura/overscroll_navigation_overlay.h",
"web_contents/aura/shadow_layer_delegate.cc",
......
......@@ -11,6 +11,7 @@ include_rules = [
"+media/video", # For Video Device monitoring in Mac.
"+mojo",
"+sql",
"+ui/aura_extra",
"+ui/webui",
"+win8/util",
......
......@@ -6,12 +6,12 @@
#include "content/browser/frame_host/navigation_entry_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/aura/image_window_delegate.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_widget_host_view.h"
#include "ui/aura/window.h"
#include "ui/aura_extra/image_window_delegate.h"
#include "ui/base/layout.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
......@@ -162,7 +162,7 @@ void OverscrollNavigationOverlay::StartObserving() {
void OverscrollNavigationOverlay::SetOverlayWindow(
scoped_ptr<aura::Window> window,
ImageWindowDelegate* delegate) {
aura_extra::ImageWindowDelegate* delegate) {
window_ = window.Pass();
if (window_.get() && window_->parent())
window_->parent()->StackChildAtTop(window_.get());
......
......@@ -13,10 +13,13 @@
struct ViewHostMsg_UpdateRect_Params;
namespace aura_extra {
class ImageWindowDelegate;
}
namespace content {
class ImageLayerDelegate;
class ImageWindowDelegate;
class OverscrollNavigationOverlayTest;
// When a history navigation is triggered at the end of an overscroll
......@@ -43,10 +46,10 @@ class CONTENT_EXPORT OverscrollNavigationOverlay
// Sets the screenshot window and the delegate. This takes ownership of
// |window|.
// Note that ImageWindowDelegate manages its own lifetime, so this function
// does not take ownership of |delegate|.
// Note that aura_extra::ImageWindowDelegate manages its own lifetime, so this
// function does not take ownership of |delegate|.
void SetOverlayWindow(scoped_ptr<aura::Window> window,
ImageWindowDelegate* delegate);
aura_extra::ImageWindowDelegate* delegate);
private:
friend class OverscrollNavigationOverlayTest;
......@@ -96,7 +99,7 @@ class CONTENT_EXPORT OverscrollNavigationOverlay
// This is the WindowDelegate of |window_|. The delegate manages its own
// lifetime (destroys itself when |window_| is destroyed).
ImageWindowDelegate* image_delegate_;
aura_extra::ImageWindowDelegate* image_delegate_;
bool loading_complete_;
bool received_paint_update_;
......
......@@ -5,7 +5,6 @@
#include "content/browser/web_contents/aura/overscroll_navigation_overlay.h"
#include "content/browser/frame_host/navigation_entry_impl.h"
#include "content/browser/web_contents/aura/image_window_delegate.h"
#include "content/browser/web_contents/web_contents_view.h"
#include "content/common/frame_messages.h"
#include "content/common/view_messages.h"
......@@ -15,6 +14,7 @@
#include "content/test/test_web_contents.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura_extra/image_window_delegate.h"
#include "ui/gfx/codec/png_codec.h"
namespace content {
......@@ -87,7 +87,8 @@ class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness {
// Create the overlay, and set the contents of the overlay window.
overlay_.reset(new OverscrollNavigationOverlay(contents()));
ImageWindowDelegate* image_delegate = new ImageWindowDelegate();
aura_extra::ImageWindowDelegate* image_delegate =
new aura_extra::ImageWindowDelegate();
scoped_ptr<aura::Window> overlay_window(
aura::test::CreateTestWindowWithDelegate(
image_delegate,
......
......@@ -21,7 +21,6 @@
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "content/browser/renderer_host/web_input_event_aura.h"
#include "content/browser/web_contents/aura/gesture_nav_simple.h"
#include "content/browser/web_contents/aura/image_window_delegate.h"
#include "content/browser/web_contents/aura/overscroll_navigation_overlay.h"
#include "content/browser/web_contents/aura/shadow_layer_delegate.h"
#include "content/browser/web_contents/aura/window_slider.h"
......@@ -52,6 +51,7 @@
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/aura_extra/image_window_delegate.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/dragdrop/drag_drop_types.h"
......@@ -116,7 +116,7 @@ RenderWidgetHostViewAura* ToRenderWidgetHostViewAura(
// The window delegate for the overscroll window. This redirects trackpad events
// to the web-contents window. The delegate destroys itself when the window is
// destroyed.
class OverscrollWindowDelegate : public ImageWindowDelegate {
class OverscrollWindowDelegate : public aura_extra::ImageWindowDelegate {
public:
OverscrollWindowDelegate(WebContentsImpl* web_contents,
OverscrollMode overscroll_mode)
......
......@@ -1399,8 +1399,6 @@
'browser/utility_process_host_impl.h',
'browser/web_contents/aura/gesture_nav_simple.cc',
'browser/web_contents/aura/gesture_nav_simple.h',
'browser/web_contents/aura/image_window_delegate.cc',
'browser/web_contents/aura/image_window_delegate.h',
'browser/web_contents/aura/overscroll_navigation_overlay.cc',
'browser/web_contents/aura/overscroll_navigation_overlay.h',
'browser/web_contents/aura/shadow_layer_delegate.cc',
......@@ -1908,6 +1906,7 @@
['use_aura==1', {
'dependencies': [
'../ui/aura/aura.gyp:aura',
'../ui/aura_extra/aura_extra.gyp:aura_extra',
'../ui/strings/ui_strings.gyp:ui_strings',
],
}, {
......
......@@ -1094,6 +1094,7 @@
['use_aura==1', {
'dependencies': [
'../ui/aura/aura.gyp:aura',
'../ui/aura_extra/aura_extra.gyp:aura_extra',
'../ui/wm/wm.gyp:wm',
]
}],
......
# Copyright 2015 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.
import("//build/config/ui.gni")
component("aura_extra") {
sources = [
"aura_extra_export.h",
"image_window_delegate.cc",
"image_window_delegate.h",
]
defines = [ "AURA_EXTRA_IMPLEMENTATION" ]
deps = [
"//base",
"//ui/aura",
"//ui/base",
"//ui/events",
"//ui/gfx",
"//ui/gfx/geometry",
]
}
include_rules = [
"+third_party/skia",
"+ui/aura",
"+ui/base",
"+ui/compositor",
"+ui/events",
"+ui/gfx",
]
# Copyright 2015 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.
{
'variables': {
'chromium_code': 1,
},
'targets': [
{
# GN version: //ui/aura_extra
'target_name': 'aura_extra',
'type': '<(component)',
'dependencies': [
'../../base/base.gyp:base',
'../aura/aura.gyp:aura',
'../base/ui_base.gyp:ui_base',
'../events/events.gyp:events',
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
],
'defines': [
'AURA_EXTRA_IMPLEMENTATION',
],
'sources': [
'aura_extra_export.h',
'image_window_delegate.cc',
'image_window_delegate.h',
],
},
],
}
// Copyright 2015 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 UI_AURA_EXTRA_EXPORT_H_
#define UI_AURA_EXTRA_EXPORT_H_
// Defines AURA_EXTRA_EXPORT so that functionality implemented by the aura-extra
// module can be exported to consumers.
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#if defined(AURA_EXTRA_IMPLEMENTATION)
#define AURA_EXTRA_EXPORT __declspec(dllexport)
#else
#define AURA_EXTRA_EXPORT __declspec(dllimport)
#endif // defined(AURA_EXTRA_IMPLEMENTATION)
#else // defined(WIN32)
#if defined(AURA_EXTRA_IMPLEMENTATION)
#define AURA_EXTRA_EXPORT __attribute__((visibility("default")))
#else
#define AURA_EXTRA_EXPORT
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define AURA_EXTRA_EXPORT
#endif
#endif // UI_AURA_EXTRA_EXPORT_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/web_contents/aura/image_window_delegate.h"
#include "ui/aura_extra/image_window_delegate.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
......@@ -13,10 +13,11 @@
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
namespace content {
namespace aura_extra {
ImageWindowDelegate::ImageWindowDelegate()
: size_mismatch_(false) {
: background_color_(SK_ColorWHITE),
size_mismatch_(false) {
}
ImageWindowDelegate::~ImageWindowDelegate() {
......@@ -69,13 +70,12 @@ void ImageWindowDelegate::OnCaptureLost() {
}
void ImageWindowDelegate::OnPaint(gfx::Canvas* canvas) {
if (image_.IsEmpty()) {
canvas->DrawColor(SK_ColorWHITE);
} else {
if (size_mismatch_)
canvas->DrawColor(SK_ColorWHITE);
canvas->DrawImageInt(image_.AsImageSkia(), 0, 0);
if (background_color_ != SK_ColorTRANSPARENT &&
(image_.IsEmpty() || size_mismatch_ || !offset_.IsZero())) {
canvas->DrawColor(background_color_);
}
if (!image_.IsEmpty())
canvas->DrawImageInt(image_.AsImageSkia(), offset_.x(), offset_.y());
}
void ImageWindowDelegate::OnDeviceScaleFactorChanged(float scale_factor) {
......@@ -98,4 +98,4 @@ bool ImageWindowDelegate::HasHitTestMask() const {
void ImageWindowDelegate::GetHitTestMask(gfx::Path* mask) const {
}
} // namespace content
} // namespace aura_extra
......@@ -2,23 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_IMAGE_WINDOW_DELEGATE_H_
#define CONTENT_BROWSER_WEB_CONTENTS_AURA_IMAGE_WINDOW_DELEGATE_H_
#ifndef UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
#define UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
#include "content/common/content_export.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura_extra/aura_extra_export.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/image/image.h"
namespace content {
namespace aura_extra {
// An ImageWindowDelegate paints an image for a Window. The delegate destroys
// itself when the Window is destroyed. The delegate does not consume any event.
class CONTENT_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
// An ImageWindowDelegate paints an image for a Window, possibly also filling
// the window with a specified backround color. The delegate does not consume
// any event.
//
// The delegate destroys itself when the Window is destroyed. This is done in
// |OnWindowDestroyed()| function which subclasses can override to prevent
// self-destroying.
class AURA_EXTRA_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
public:
ImageWindowDelegate();
void SetImage(const gfx::Image& image);
void set_background_color(SkColor color) { background_color_ = color; }
void set_image_offset(gfx::Vector2d offset) { offset_ = offset; }
bool has_image() const { return !image_.IsEmpty(); }
protected:
......@@ -46,17 +57,20 @@ class CONTENT_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
void GetHitTestMask(gfx::Path* mask) const override;
protected:
SkColor background_color_;
gfx::Image image_;
gfx::Vector2d offset_;
gfx::Size window_size_;
// Keeps track of whether the window size matches the image size or not. If
// the image size is smaller than the window size, then the delegate paints a
// white background for the missing regions.
// the image size is smaller than the window size, then the delegate fills the
// missing regions with |background_color_| (defult is white).
bool size_mismatch_;
DISALLOW_COPY_AND_ASSIGN(ImageWindowDelegate);
};
} // namespace content
} // namespace aura_extra
#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_IMAGE_WINDOW_DELEGATE_H_
#endif // UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment