Commit faef3c50 authored by danakj@chromium.org's avatar danakj@chromium.org
Browse files

[chromium] Add setters to WebFilterOperation for IPC pickling

https://bugs.webkit.org/show_bug.cgi?id=97147

Reviewed by James Robinson.

Source/Platform:

These methods allow us to restore a WebFilterOperation from a blob
of opaque data. The pickling code needs to be able to create an
empty object and then fill in the pieces, so these setters allow it
to do so.

Test: WebFilterOperationsTest.saveAndRestore

* chromium/public/WebFilterOperation.h:
(WebKit::WebFilterOperation::amount):
(WebKit::WebFilterOperation::dropShadowOffset):
(WebKit::WebFilterOperation::matrix):
(WebKit::WebFilterOperation::zoomRect):
(WebFilterOperation):
(WebKit::WebFilterOperation::createEmptyFilter):
(WebKit::WebFilterOperation::setType):
(WebKit::WebFilterOperation::setAmount):
(WebKit::WebFilterOperation::setDropShadowOffset):
(WebKit::WebFilterOperation::setDropShadowColor):
(WebKit::WebFilterOperation::setMatrix):
(WebKit::WebFilterOperation::setZoomRect):
* chromium/src/WebFilterOperation.cpp:

Source/WebKit/chromium:

* tests/FilterOperationsTest.cpp:
(WebKit):
(WebKit::TEST):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@129243 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5a2e055e
2012-09-21 Dana Jansens <danakj@chromium.org>
[chromium] Add setters to WebFilterOperation for IPC pickling
https://bugs.webkit.org/show_bug.cgi?id=97147
Reviewed by James Robinson.
These methods allow us to restore a WebFilterOperation from a blob
of opaque data. The pickling code needs to be able to create an
empty object and then fill in the pieces, so these setters allow it
to do so.
Test: WebFilterOperationsTest.saveAndRestore
* chromium/public/WebFilterOperation.h:
(WebKit::WebFilterOperation::amount):
(WebKit::WebFilterOperation::dropShadowOffset):
(WebKit::WebFilterOperation::matrix):
(WebKit::WebFilterOperation::zoomRect):
(WebFilterOperation):
(WebKit::WebFilterOperation::createEmptyFilter):
(WebKit::WebFilterOperation::setType):
(WebKit::WebFilterOperation::setAmount):
(WebKit::WebFilterOperation::setDropShadowOffset):
(WebKit::WebFilterOperation::setDropShadowColor):
(WebKit::WebFilterOperation::setMatrix):
(WebKit::WebFilterOperation::setZoomRect):
* chromium/src/WebFilterOperation.cpp:
2012-09-20 Keishi Hattori <keishi@webkit.org>
[Chromium ] Add new localized string, OtherDateLabel, to be used in input type=date datalist UI
......
......@@ -55,12 +55,23 @@ public:
float amount() const
{
WEBKIT_ASSERT(m_type == FilterTypeGrayscale
|| m_type == FilterTypeSepia
|| m_type == FilterTypeSaturate
|| m_type == FilterTypeHueRotate
|| m_type == FilterTypeInvert
|| m_type == FilterTypeBrightness
|| m_type == FilterTypeContrast
|| m_type == FilterTypeOpacity
|| m_type == FilterTypeBlur
|| m_type == FilterTypeDropShadow
|| m_type == FilterTypeZoom);
return m_amount;
}
WebPoint dropShadowOffset() const
{
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
return WebPoint(m_dropShadowOffset);
return m_dropShadowOffset;
}
WebColor dropShadowColor() const
{
......@@ -69,16 +80,16 @@ public:
}
const SkScalar* matrix() const
{
WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
return m_matrix;
}
WebRect zoomRect() const
{
WEBKIT_ASSERT(m_type == FilterTypeZoom);
return WebRect(m_zoomRect);
return m_zoomRect;
}
#define WEBKIT_HAS_NEW_WEBFILTEROPERATION_API 1
static WebFilterOperation createGrayscaleFilter(float amount) { return WebFilterOperation(FilterTypeGrayscale, amount); }
static WebFilterOperation createSepiaFilter(float amount) { return WebFilterOperation(FilterTypeSepia, amount); }
static WebFilterOperation createSaturateFilter(float amount) { return WebFilterOperation(FilterTypeSaturate, amount); }
......@@ -94,6 +105,46 @@ public:
bool equals(const WebFilterOperation& other) const;
// Methods for restoring a WebFilterOperation.
static WebFilterOperation createEmptyFilter() { return WebFilterOperation(FilterTypeGrayscale, 0.0); }
void setType(FilterType type) { m_type = type; }
void setAmount(float amount)
{
WEBKIT_ASSERT(m_type == FilterTypeGrayscale
|| m_type == FilterTypeSepia
|| m_type == FilterTypeSaturate
|| m_type == FilterTypeHueRotate
|| m_type == FilterTypeInvert
|| m_type == FilterTypeBrightness
|| m_type == FilterTypeContrast
|| m_type == FilterTypeOpacity
|| m_type == FilterTypeBlur
|| m_type == FilterTypeDropShadow
|| m_type == FilterTypeZoom);
m_amount = amount;
}
void setDropShadowOffset(WebPoint offset)
{
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
m_dropShadowOffset = offset;
}
void setDropShadowColor(WebColor color)
{
WEBKIT_ASSERT(m_type == FilterTypeDropShadow);
m_dropShadowColor = color;
}
void setMatrix(const SkScalar matrix[20])
{
WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
for (unsigned i = 0; i < 20; ++i)
m_matrix[i] = matrix[i];
}
void setZoomRect(WebRect rect)
{
WEBKIT_ASSERT(m_type == FilterTypeZoom);
m_zoomRect = rect;
}
private:
FilterType m_type;
......
2012-09-21 Dana Jansens <danakj@chromium.org>
[chromium] Add setters to WebFilterOperation for IPC pickling
https://bugs.webkit.org/show_bug.cgi?id=97147
Reviewed by James Robinson.
* tests/FilterOperationsTest.cpp:
(WebKit):
(WebKit::TEST):
2012-09-21 Tony Chang <tony@chromium.org>
 
[chromium] Unreviewed, remove duplicate section of WebKit.gyp pointed out by Nico.
......
......@@ -89,5 +89,108 @@ TEST(WebFilterOperationsTest, getOutsetsDropShadow)
EXPECT_EQ(54, left);
}
#define SAVE_RESTORE_AMOUNT(Type, a) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
EXPECT_EQ(a, op.amount()); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
EXPECT_NE(a, op2.amount()); \
\
op2.setAmount(a); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
EXPECT_EQ(a, op2.amount()); \
}
#define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(Type, a, b, c) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a, b, c); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
EXPECT_EQ(a, op.dropShadowOffset()); \
EXPECT_EQ(b, op.amount()); \
EXPECT_EQ(c, op.dropShadowColor()); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
EXPECT_NE(a, op2.dropShadowOffset()); \
EXPECT_NE(b, op2.amount()); \
EXPECT_NE(c, op2.dropShadowColor()); \
\
op2.setDropShadowOffset(a); \
op2.setAmount(b); \
op2.setDropShadowColor(c); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
EXPECT_EQ(a, op2.dropShadowOffset()); \
EXPECT_EQ(b, op2.amount()); \
EXPECT_EQ(c, op2.dropShadowColor()); \
}
#define SAVE_RESTORE_MATRIX(Type, a) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
for (unsigned i = 0; i < 20; ++i) \
EXPECT_EQ(a[i], op.matrix()[i]); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
for (unsigned i = 0; i < 20; ++i) \
EXPECT_NE(a[i], op2.matrix()[i]); \
\
op2.setMatrix(a); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
for (unsigned i = 0; i < 20; ++i) \
EXPECT_EQ(a[i], op.matrix()[i]); \
}
#define SAVE_RESTORE_ZOOMRECT_AMOUNT(Type, a, b) \
{ \
WebFilterOperation op = WebFilterOperation::create##Type##Filter(a, b); \
EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \
EXPECT_EQ(a, op.zoomRect()); \
EXPECT_EQ(b, op.amount()); \
\
WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \
op2.setType(WebFilterOperation::FilterType##Type); \
\
EXPECT_NE(a, op2.zoomRect()); \
EXPECT_NE(b, op2.amount()); \
\
op2.setZoomRect(a); \
op2.setAmount(b); \
\
EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \
EXPECT_EQ(a, op2.zoomRect()); \
EXPECT_EQ(b, op2.amount()); \
}
TEST(WebFilterOperationsTest, saveAndRestore)
{
SAVE_RESTORE_AMOUNT(Grayscale, 0.6f);
SAVE_RESTORE_AMOUNT(Sepia, 0.6f);
SAVE_RESTORE_AMOUNT(Saturate, 0.6f);
SAVE_RESTORE_AMOUNT(HueRotate, 0.6f);
SAVE_RESTORE_AMOUNT(Invert, 0.6f);
SAVE_RESTORE_AMOUNT(Brightness, 0.6f);
SAVE_RESTORE_AMOUNT(Contrast, 0.6f);
SAVE_RESTORE_AMOUNT(Opacity, 0.6f);
SAVE_RESTORE_AMOUNT(Blur, 0.6f);
SAVE_RESTORE_OFFSET_AMOUNT_COLOR(DropShadow, WebPoint(3, 4), 0.4f, 0xffffff00);
SkScalar matrix[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
SAVE_RESTORE_MATRIX(ColorMatrix, matrix);
SAVE_RESTORE_ZOOMRECT_AMOUNT(Zoom, WebRect(20, 19, 18, 17), 32);
}
}
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