ginebra2/WebChromeSnippet.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include "WebChromeSnippet.h"
    22 #include "WebChromeSnippet.h"
    20 #include "WebChromeItem.h"
    23 #include "WebChromeItem.h"
    21 #include "PopupWebChromeItem.h"
    24 #include "PopupWebChromeItem.h"
    22 #include "ChromeRenderer.h"
    25 #include "ChromeRenderer.h"
    27 
    30 
    28 namespace GVA {
    31 namespace GVA {
    29 
    32 
    30   static WebChromeItem * newChromeItem(
    33   static WebChromeItem * newChromeItem(
    31       ChromeWidget * chrome,
    34       ChromeWidget * chrome,
    32       const QRectF& ownerArea,
       
    33       const QWebElement & element)
    35       const QWebElement & element)
    34   {
    36   {
    35     QString type = element.attribute("data-GinebraItemType", "normal");
    37     QString type = element.attribute("data-GinebraItemType", "normal");
    36 
    38 
    37     if (type == "popup") {
    39     if (type == "popup") {
    38       return new PopupWebChromeItem(ownerArea, chrome, element);
    40       QString modal = element.attribute("data-GinebraPopupModal", "true");
       
    41       return new PopupWebChromeItem(chrome, element, 0, modal == "true");
    39     }
    42     }
    40 
    43 
    41     return new WebChromeItem(ownerArea, chrome, element);
    44     return new WebChromeItem(chrome, element);
    42   }
    45   }
    43 
    46 
    44   WebChromeSnippet::WebChromeSnippet(
    47   WebChromeSnippet::WebChromeSnippet(
    45           const QString & elementId,
    48           const QString & elementId,
    46           ChromeWidget * chrome,
    49           ChromeWidget * chrome,
    47           const QRectF& ownerArea,
       
    48           const QWebElement & element)
    50           const QWebElement & element)
    49     : ChromeSnippet(elementId, chrome, newChromeItem(chrome, ownerArea, element), element)
    51     : ChromeSnippet(elementId, chrome, newChromeItem(chrome, element), element)
    50 
    52 
    51   {
    53   {
    52     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
    54     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
    53     item->init(this);
    55     item->init(this);
    54   }
    56   }
    55 
    57 
    56   WebChromeSnippet::~WebChromeSnippet()
    58   WebChromeSnippet::~WebChromeSnippet()
    57   {
    59   {
    58   }
    60   }
    59   
    61 
    60   WebChromeItem * WebChromeSnippet::item()
    62   WebChromeItem * WebChromeSnippet::item()
    61   {
    63   {
    62     return static_cast<WebChromeItem*> (widget());
    64     return static_cast<WebChromeItem*> (widget());
    63   }
    65   }
    64 
    66 
    65   void WebChromeSnippet:: grabFocus()
    67   void WebChromeSnippet:: grabFocus()
    66   {
    68   {
    67     //qDebug() << "WebChromeSnippet::grabFocus";
    69     //qDebug() << "WebChromeSnippet::grabFocus";
    68     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
    70     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
    69     item->grabFocus();
    71     item->grabFocus();
    70   } 
    72   }
    71 
    73 
    72   void WebChromeSnippet:: updateOwnerArea()
    74   void WebChromeSnippet:: updateOwnerArea()
    73   {
    75   {
       
    76 
    74     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
    77     WebChromeItem * item = static_cast<WebChromeItem*> (widget());
    75     //Setting owner area also resets the item's size and preferred size
    78     item->updateSizes();
    76     item->setOwnerArea(m_chrome->getSnippetRect(m_elementId));
    79     //TODO: Revisit this, don't use owner area
    77     //qDebug() << WebChromeSnippet::updateOwnerArea: id: " << m_elementId << " element rect: " << item->ownerArea();
    80     //item->setCachedHandlers(m_chrome->dom()->getCachedHandlers(m_elementId, item->ownerArea()));
    78     //NB: Should move this to WebChromeItem::setOwnerArea()?
    81 
    79     item->setCachedHandlers(m_chrome->dom()->getCachedHandlers(m_elementId, item->ownerArea()));
       
    80   }
    82   }
    81 
    83 
    82 } // endof namespace GVA
    84 } // endof namespace GVA