Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: webkit/port/platform/graphics/ThemeHelperWin.cpp

Issue 9008: Add support for arbitrarily transformed Windows buttons text field... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "FloatRect.h"
28 #include "GraphicsContext.h"
29 #include "ThemeHelperWin.h"
30
31 namespace WebCore {
32
33 static void IntRectToRECT(const IntRect& ir, RECT* r)
M-A Ruel 2008/11/03 20:18:46 I guess we can't use operator RECT() because it's
34 {
35 r->left = ir.x();
36 r->top = ir.y();
37 r->right = ir.right();
38 r->bottom = ir.bottom();
39 }
40
41 ThemeHelperWin::ThemeHelperWin(GraphicsContext* context,
42 const IntRect& rect)
43 : m_orgContext(context)
44 , m_orgMatrix(context->getCTM())
45 , m_orgRect(rect)
46 {
47 if (m_orgMatrix.b() != 0 || // Y skew
48 m_orgMatrix.c() != 0) { // X skew
49 // Complicated effects, make a copy and draw the bitmap there.
50 m_type = COPY;
51 m_rect.left = 0;
52 m_rect.top = 0;
53 m_rect.right = rect.width();
54 m_rect.bottom = rect.height();
55
56 m_newBuffer.set(ImageBuffer::create(rect.size(), false).release());
57
58 // Theme drawing messes with the transparency.
59 // TODO(brettw) Ideally, we would leave this transparent, but I was
60 // having problems with button drawing, so we fill with white. Buttons
61 // looked good with transparent here and no fixing up of the alpha
62 // later, but text areas didn't. This makes text areas look good but
63 // gives buttons a white halo. Is there a way to fix this? I think
64 // buttons actually have antialised edges which is just not possible
65 // to handle on a transparent background given that it messes with the
66 // alpha channel.
67 FloatRect newContextRect(0, 0, rect.width(), rect.height());
68 GraphicsContext* newContext = m_newBuffer->context();
69 newContext->setFillColor(Color::white);
70 newContext->fillRect(newContextRect);
71
72 return;
73 }
74
75 if (m_orgMatrix.a() != 1.0 || // X scale
76 m_orgMatrix.d() != 1.0) { // Y scale
77 // Only a scaling is applied.
78 m_type = SCALE;
79
80 // Save the transformed coordinates to draw.
81 IntRectToRECT(m_orgMatrix.mapRect(rect), &m_rect);
82
83 m_orgContext->save();
84 m_orgContext->concatCTM(m_orgContext->getCTM().inverse());
85 return;
86 }
87
88 // Nothing interesting.
89 IntRectToRECT(rect, &m_rect);
90 m_type = ORIGINAL;
91 }
92
93 ThemeHelperWin::~ThemeHelperWin()
94 {
95 switch (m_type) {
96 case SCALE:
97 m_orgContext->restore();
98 break;
99 case COPY: {
100 // Copy the duplicate bitmap with our control to the original canvas.
101 FloatRect destRect(m_orgRect);
102 m_newBuffer->context()->platformContext()->canvas()->
103 getTopPlatformDevice().fixupAlphaBeforeCompositing();
104 m_orgContext->drawImage(m_newBuffer->image(), destRect);
105 break;
106 }
107 case ORIGINAL:
108 break;
109 }
110 }
111
112 RECT ThemeHelperWin::transformRect(const RECT& r) const
113 {
114 IntRect src(r.left, r.top, r.right - r.left, r.bottom - r.top);
115 IntRect dest;
116 switch (m_type) {
117 case SCALE:
118 dest = m_orgMatrix.mapRect(src);
119 break;
120 case COPY:
121 dest = src;
122 dest.move(-m_orgRect.x(), -m_orgRect.y());
123 break;
124 case ORIGINAL:
125 break;
126 }
127
128 RECT output;
129 IntRectToRECT(dest, &output);
130 return output;
131 }
132
133 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698