Home | History | Annotate | Download | only in android
      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 
     39 Widget::Widget(PlatformWidget widget)
     40 {
     41     init(widget);
     42 }
     43 
     44 Widget::~Widget()
     45 {
     46     ASSERT(!parent());
     47     releasePlatformWidget();
     48 }
     49 
     50 IntRect Widget::frameRect() const
     51 {
     52     if (!platformWidget())
     53         return m_frame;
     54     return platformWidget()->getBounds();
     55 }
     56 
     57 void Widget::setFocus()
     58 {
     59     notImplemented();
     60 }
     61 
     62 void Widget::paint(GraphicsContext* ctx, const IntRect& r)
     63 {
     64     // FIXME: in what case, will this be called for the top frame?
     65     if (!platformWidget())
     66         return;
     67     platformWidget()->draw(ctx, r);
     68 }
     69 
     70 void Widget::releasePlatformWidget()
     71 {
     72     Release(platformWidget());
     73 }
     74 
     75 void Widget::retainPlatformWidget()
     76 {
     77     Retain(platformWidget());
     78 }
     79 
     80 void Widget::setCursor(const Cursor& cursor)
     81 {
     82     notImplemented();
     83 }
     84 
     85 void Widget::show()
     86 {
     87     notImplemented();
     88 }
     89 
     90 void Widget::hide()
     91 {
     92     notImplemented();
     93 }
     94 
     95 void Widget::setFrameRect(const IntRect& rect)
     96 {
     97     m_frame = rect;
     98     // platformWidget() is 0 when called from Scrollbar
     99     if (!platformWidget())
    100         return;
    101     platformWidget()->setLocation(rect.x(), rect.y());
    102     platformWidget()->setSize(rect.width(), rect.height());
    103 }
    104 
    105 void Widget::setIsSelected(bool isSelected)
    106 {
    107     notImplemented();
    108 }
    109 
    110 int Widget::screenWidth() const
    111 {
    112     const Widget* widget = this;
    113     while (!widget->isFrameView()) {
    114         widget = widget->parent();
    115         if (!widget)
    116             break;
    117     }
    118     if (!widget)
    119         return 0;
    120     android::WebViewCore* core = android::WebViewCore::getWebViewCore(
    121         static_cast<const ScrollView*>(widget));
    122     if (!core)
    123         return 0;
    124     return core->screenWidth();
    125 }
    126 
    127 } // WebCore namepsace
    128