ginebra2/WebChromeSnippet.cpp
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "WebChromeSnippet.h"
       
    20 #include "WebChromeItem.h"
       
    21 #include "PopupWebChromeItem.h"
       
    22 #include "ChromeRenderer.h"
       
    23 #include "ChromeWidget.h"
       
    24 #include "ChromeDOM.h"
       
    25 #include <QWebElement>
       
    26 #include <QDebug>
       
    27 
       
    28 namespace GVA {
       
    29 
       
    30   static WebChromeItem * newChromeItem(
       
    31       ChromeWidget * chrome,
       
    32       const QRectF& ownerArea,
       
    33       const QWebElement & element)
       
    34   {
       
    35     QString type = element.attribute("data-GinebraItemType", "normal");
       
    36 
       
    37     if (type == "popup") {
       
    38       return new PopupWebChromeItem(ownerArea, chrome, element);
       
    39     }
       
    40 
       
    41     return new WebChromeItem(ownerArea, chrome, element);
       
    42   }
       
    43 
       
    44   WebChromeSnippet::WebChromeSnippet(
       
    45           const QString & elementId,
       
    46           ChromeWidget * chrome,
       
    47           const QRectF& ownerArea,
       
    48           const QWebElement & element)
       
    49     : ChromeSnippet(elementId, chrome, newChromeItem(chrome, ownerArea, element), element)
       
    50 
       
    51   {
       
    52     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
       
    53     item->init(this);
       
    54   }
       
    55 
       
    56   WebChromeSnippet::~WebChromeSnippet()
       
    57   {
       
    58   }
       
    59   
       
    60   WebChromeItem * WebChromeSnippet::item()
       
    61   {
       
    62     return static_cast<WebChromeItem*> (widget());
       
    63   }
       
    64 
       
    65   void WebChromeSnippet:: grabFocus()
       
    66   {
       
    67     //qDebug() << "WebChromeSnippet::grabFocus";
       
    68     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
       
    69     item->grabFocus();
       
    70   } 
       
    71 
       
    72   void WebChromeSnippet:: updateOwnerArea()
       
    73   {
       
    74     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
       
    75     //Setting owner area also resets the item's size and preferred size
       
    76     item->setOwnerArea(m_chrome->getSnippetRect(m_elementId));
       
    77     //qDebug() << WebChromeSnippet::updateOwnerArea: id: " << m_elementId << " element rect: " << item->ownerArea();
       
    78     //NB: Should move this to WebChromeItem::setOwnerArea()?
       
    79     item->setCachedHandlers(m_chrome->dom()->getCachedHandlers(m_elementId, item->ownerArea()));
       
    80   }
       
    81 
       
    82 } // endof namespace GVA