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

Side by Side Diff: Source/WebCore/platform/mac/WidgetMac.mm

Issue 13713003: Remove all of WebCore/platform/mac which is not mentioned in WebCore.gypi. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added back a couple needed headers Created 7 years, 8 months 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
« no previous file with comments | « Source/WebCore/platform/mac/WebWindowAnimation.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008, 2010, 2011 Apple Inc. All rights reserv ed.
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 #import "config.h"
27 #import "Widget.h"
28
29
30 #import "BlockExceptions.h"
31 #import "Chrome.h"
32 #import "Cursor.h"
33 #import "Document.h"
34 #import "Font.h"
35 #import "Frame.h"
36 #import "GraphicsContext.h"
37 #import "NotImplemented.h"
38 #import "Page.h"
39 #import "PlatformMouseEvent.h"
40 #import "ScrollView.h"
41 #import "WebCoreFrameView.h"
42 #import "WebCoreView.h"
43 #import <wtf/RetainPtr.h>
44
45 @interface NSWindow (WebWindowDetails)
46 - (BOOL)_needsToResetDragMargins;
47 - (void)_setNeedsToResetDragMargins:(BOOL)needs;
48 @end
49
50 @interface NSView (WebSetSelectedMethods)
51 - (void)setIsSelected:(BOOL)isSelected;
52 - (void)webPlugInSetIsSelected:(BOOL)isSelected;
53 @end
54
55 @interface NSView (Widget)
56 - (void)visibleRectDidChange;
57 @end
58
59 namespace WebCore {
60
61 class WidgetPrivate {
62 public:
63 WidgetPrivate()
64 : previousVisibleRect(NSZeroRect)
65 {
66 }
67
68 NSRect previousVisibleRect;
69 };
70
71 static void safeRemoveFromSuperview(NSView *view)
72 {
73 // If the the view is the first responder, then set the window's first respo nder to nil so
74 // we don't leave the window pointing to a view that's no longer in it.
75 NSWindow *window = [view window];
76 NSResponder *firstResponder = [window firstResponder];
77 if ([firstResponder isKindOfClass:[NSView class]] && [(NSView *)firstRespond er isDescendantOf:view])
78 [window makeFirstResponder:nil];
79
80 // Suppress the resetting of drag margins since we know we can't affect them .
81 BOOL resetDragMargins = [window _needsToResetDragMargins];
82 [window _setNeedsToResetDragMargins:NO];
83 [view removeFromSuperview];
84 [window _setNeedsToResetDragMargins:resetDragMargins];
85 }
86
87 Widget::Widget(NSView *view)
88 : m_data(new WidgetPrivate)
89 {
90 init(view);
91 }
92
93 Widget::~Widget()
94 {
95 delete m_data;
96 }
97
98 // FIXME: Should move this to Chrome; bad layering that this knows about Frame.
99 void Widget::setFocus(bool focused)
100 {
101 if (!focused)
102 return;
103
104 Frame* frame = Frame::frameForWidget(this);
105 if (!frame)
106 return;
107
108 BEGIN_BLOCK_OBJC_EXCEPTIONS;
109
110 // Call this even when there is no platformWidget(). WK2 will focus on the w idget in the UIProcess.
111 NSView *view = [platformWidget() _webcore_effectiveFirstResponder];
112 if (Page* page = frame->page())
113 page->chrome()->focusNSView(view);
114
115 END_BLOCK_OBJC_EXCEPTIONS;
116 }
117
118 void Widget::setCursor(const Cursor& cursor)
119 {
120 ScrollView* view = root();
121 if (!view)
122 return;
123 view->hostWindow()->setCursor(cursor);
124 }
125
126 void Widget::show()
127 {
128 if (isSelfVisible())
129 return;
130
131 setSelfVisible(true);
132
133 BEGIN_BLOCK_OBJC_EXCEPTIONS;
134 [getOuterView() setHidden:NO];
135 END_BLOCK_OBJC_EXCEPTIONS;
136 }
137
138 void Widget::hide()
139 {
140 if (!isSelfVisible())
141 return;
142
143 setSelfVisible(false);
144
145 BEGIN_BLOCK_OBJC_EXCEPTIONS;
146 [getOuterView() setHidden:YES];
147 END_BLOCK_OBJC_EXCEPTIONS;
148 }
149
150 IntRect Widget::frameRect() const
151 {
152 if (!platformWidget())
153 return m_frame;
154
155 BEGIN_BLOCK_OBJC_EXCEPTIONS;
156 return enclosingIntRect([getOuterView() frame]);
157 END_BLOCK_OBJC_EXCEPTIONS;
158
159 return m_frame;
160 }
161
162 void Widget::setFrameRect(const IntRect& rect)
163 {
164 m_frame = rect;
165
166 BEGIN_BLOCK_OBJC_EXCEPTIONS;
167 NSView *outerView = getOuterView();
168 if (!outerView)
169 return;
170
171 // Take a reference to this Widget, because sending messages to outerView ca n invoke arbitrary
172 // code, which can deref it.
173 RefPtr<Widget> protectedThis(this);
174
175 NSRect visibleRect = [outerView visibleRect];
176 NSRect f = rect;
177 if (!NSEqualRects(f, [outerView frame])) {
178 [outerView setFrame:f];
179 [outerView setNeedsDisplay:NO];
180 } else if (!NSEqualRects(visibleRect, m_data->previousVisibleRect) && [outer View respondsToSelector:@selector(visibleRectDidChange)])
181 [outerView visibleRectDidChange];
182
183 m_data->previousVisibleRect = visibleRect;
184 END_BLOCK_OBJC_EXCEPTIONS;
185 }
186
187 NSView *Widget::getOuterView() const
188 {
189 NSView *view = platformWidget();
190
191 // If this widget's view is a WebCoreFrameScrollView then we
192 // resize its containing view, a WebFrameView.
193 if ([view conformsToProtocol:@protocol(WebCoreFrameScrollView)]) {
194 view = [view superview];
195 ASSERT(view);
196 }
197
198 return view;
199 }
200
201 void Widget::paint(GraphicsContext* p, const IntRect& r)
202 {
203 if (p->paintingDisabled())
204 return;
205 NSView *view = getOuterView();
206
207 // Take a reference to this Widget, because sending messages to the views ca n invoke arbitrary
208 // code, which can deref it.
209 RefPtr<Widget> protectedThis(this);
210
211 NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
212 if (currentContext == [[view window] graphicsContext] || ![currentContext is DrawingToScreen]) {
213 // This is the common case of drawing into a window or printing.
214 BEGIN_BLOCK_OBJC_EXCEPTIONS;
215 [view displayRectIgnoringOpacity:[view convertRect:r fromView:[view supe rview]]];
216 END_BLOCK_OBJC_EXCEPTIONS;
217 } else {
218 // This is the case of drawing into a bitmap context other than a window backing store. It gets hit beneath
219 // -cacheDisplayInRect:toBitmapImageRep:, and when painting into composi ting layers.
220
221 // Transparent subframes are in fact implemented with scroll views that return YES from -drawsBackground (whenever the WebView
222 // itself is in drawsBackground mode). In the normal drawing code path, the scroll views are never asked to draw the background,
223 // so this is not an issue, but in this code path they are, so the follo wing code temporarily turns background drwaing off.
224 NSView *innerView = platformWidget();
225 NSScrollView *scrollView = 0;
226 if ([innerView conformsToProtocol:@protocol(WebCoreFrameScrollView)]) {
227 ASSERT([innerView isKindOfClass:[NSScrollView class]]);
228 NSScrollView *scrollView = static_cast<NSScrollView *>(innerView);
229 // -copiesOnScroll will return NO whenever the content view is not f ully opaque.
230 if ([scrollView drawsBackground] && ![[scrollView contentView] copie sOnScroll])
231 [scrollView setDrawsBackground:NO];
232 else
233 scrollView = 0;
234 }
235
236 CGContextRef cgContext = p->platformContext();
237 ASSERT(cgContext == [currentContext graphicsPort]);
238 CGContextSaveGState(cgContext);
239
240 NSRect viewFrame = [view frame];
241 NSRect viewBounds = [view bounds];
242 // Set up the translation and (flipped) orientation of the graphics cont ext. In normal drawing, AppKit does it as it descends down
243 // the view hierarchy.
244 CGContextTranslateCTM(cgContext, viewFrame.origin.x - viewBounds.origin. x, viewFrame.origin.y + viewFrame.size.height + viewBounds.origin.y);
245 CGContextScaleCTM(cgContext, 1, -1);
246
247 BEGIN_BLOCK_OBJC_EXCEPTIONS;
248 {
249 NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWit hGraphicsPort:cgContext flipped:YES];
250 [view displayRectIgnoringOpacity:[view convertRect:r fromView:[view superview]] inContext:nsContext];
251 }
252 END_BLOCK_OBJC_EXCEPTIONS;
253
254 CGContextRestoreGState(cgContext);
255
256 if (scrollView)
257 [scrollView setDrawsBackground:YES];
258 }
259 }
260
261 void Widget::setIsSelected(bool isSelected)
262 {
263 NSView *view = platformWidget();
264
265 BEGIN_BLOCK_OBJC_EXCEPTIONS;
266 if ([view respondsToSelector:@selector(webPlugInSetIsSelected:)])
267 [view webPlugInSetIsSelected:isSelected];
268 else if ([view respondsToSelector:@selector(setIsSelected:)])
269 [view setIsSelected:isSelected];
270 END_BLOCK_OBJC_EXCEPTIONS;
271 }
272
273 void Widget::removeFromSuperview()
274 {
275 BEGIN_BLOCK_OBJC_EXCEPTIONS;
276 safeRemoveFromSuperview(getOuterView());
277 END_BLOCK_OBJC_EXCEPTIONS;
278 }
279
280 // These are here to deal with flipped coords on Mac.
281 IntRect Widget::convertFromRootToContainingWindow(const Widget* rootWidget, cons t IntRect& rect)
282 {
283 if (!rootWidget->platformWidget())
284 return rect;
285
286 BEGIN_BLOCK_OBJC_EXCEPTIONS;
287 return enclosingIntRect([rootWidget->platformWidget() convertRect:rect toVie w:nil]);
288 END_BLOCK_OBJC_EXCEPTIONS;
289
290 return rect;
291 }
292
293 IntRect Widget::convertFromContainingWindowToRoot(const Widget* rootWidget, cons t IntRect& rect)
294 {
295 if (!rootWidget->platformWidget())
296 return rect;
297
298 BEGIN_BLOCK_OBJC_EXCEPTIONS;
299 return enclosingIntRect([rootWidget->platformWidget() convertRect:rect fromV iew:nil]);
300 END_BLOCK_OBJC_EXCEPTIONS;
301
302 return rect;
303 }
304
305 IntPoint Widget::convertFromRootToContainingWindow(const Widget* rootWidget, con st IntPoint& point)
306 {
307 if (!rootWidget->platformWidget())
308 return point;
309
310 BEGIN_BLOCK_OBJC_EXCEPTIONS;
311 return IntPoint([rootWidget->platformWidget() convertPoint:point toView:nil] );
312 END_BLOCK_OBJC_EXCEPTIONS;
313 return point;
314 }
315
316 IntPoint Widget::convertFromContainingWindowToRoot(const Widget* rootWidget, con st IntPoint& point)
317 {
318 if (!rootWidget->platformWidget())
319 return point;
320
321 BEGIN_BLOCK_OBJC_EXCEPTIONS;
322 return IntPoint([rootWidget->platformWidget() convertPoint:point fromView:ni l]);
323 END_BLOCK_OBJC_EXCEPTIONS;
324
325 return point;
326 }
327
328 NSView *Widget::platformWidget() const
329 {
330 return m_widget.get();
331 }
332
333 void Widget::setPlatformWidget(NSView *widget)
334 {
335 if (widget == m_widget)
336 return;
337
338 m_widget = widget;
339 m_data->previousVisibleRect = NSZeroRect;
340 }
341
342 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebCore/platform/mac/WebWindowAnimation.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698