1 /*
2 * Copyright 2007, The Android Open Source Project
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 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * 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 THE COPYRIGHT HOLDERS ``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 "Widget.h"
28
29 #include "Font.h"
30 #include "FrameView.h"
31 #include "GraphicsContext.h"
32 #include "NotImplemented.h"
33 #include "WebCoreFrameBridge.h"
34 #include "WebCoreViewBridge.h"
35 #include "WebViewCore.h"
36
37 namespace WebCore {
38
Widget(PlatformWidget widget)39 Widget::Widget(PlatformWidget widget)
40 {
41 init(widget);
42 }
43
~Widget()44 Widget::~Widget()
45 {
46 ASSERT(!parent());
47 releasePlatformWidget();
48 }
49
frameRect() const50 IntRect Widget::frameRect() const
51 {
52 // FIXME: use m_frame instead?
53 if (!platformWidget())
54 return IntRect(0, 0, 0, 0);
55 return platformWidget()->getBounds();
56 }
57
setFocus()58 void Widget::setFocus()
59 {
60 notImplemented();
61 }
62
paint(GraphicsContext * ctx,const IntRect & r)63 void Widget::paint(GraphicsContext* ctx, const IntRect& r)
64 {
65 // FIXME: in what case, will this be called for the top frame?
66 if (!platformWidget())
67 return;
68 platformWidget()->draw(ctx, r);
69 }
70
releasePlatformWidget()71 void Widget::releasePlatformWidget()
72 {
73 Release(platformWidget());
74 }
75
retainPlatformWidget()76 void Widget::retainPlatformWidget()
77 {
78 Retain(platformWidget());
79 }
80
setCursor(const Cursor & cursor)81 void Widget::setCursor(const Cursor& cursor)
82 {
83 notImplemented();
84 }
85
show()86 void Widget::show()
87 {
88 notImplemented();
89 }
90
hide()91 void Widget::hide()
92 {
93 notImplemented();
94 }
95
setFrameRect(const IntRect & rect)96 void Widget::setFrameRect(const IntRect& rect)
97 {
98 // FIXME: set m_frame instead?
99 // platformWidget() is NULL when called from Scrollbar
100 if (!platformWidget())
101 return;
102 platformWidget()->setLocation(rect.x(), rect.y());
103 platformWidget()->setSize(rect.width(), rect.height());
104 }
105
setIsSelected(bool isSelected)106 void Widget::setIsSelected(bool isSelected)
107 {
108 notImplemented();
109 }
110
screenWidth() const111 int Widget::screenWidth() const
112 {
113 const Widget* widget = this;
114 while (!widget->isFrameView()) {
115 widget = widget->parent();
116 if (!widget)
117 break;
118 }
119 if (!widget)
120 return 0;
121 android::WebViewCore* core = android::WebViewCore::getWebViewCore(
122 static_cast<const ScrollView*>(widget));
123 if (!core)
124 return 0;
125 return core->screenWidth();
126 }
127
128 } // WebCore namepsace
129