Home | History | Annotate | Download | only in qt
      1 /*
      2  * This file is part of the popup menu implementation for <select> elements in WebCore.
      3  *
      4  * Copyright (C) 2008, 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
      5  * Copyright (C) 2006 Apple Computer, Inc.
      6  * Copyright (C) 2006 Michael Emmel mike.emmel (at) gmail.com
      7  * Coypright (C) 2006 Nikolas Zimmermann <zimmermann (at) kde.org>
      8  *
      9  * This library is free software; you can redistribute it and/or
     10  * modify it under the terms of the GNU Library General Public
     11  * License as published by the Free Software Foundation; either
     12  * version 2 of the License, or (at your option) any later version.
     13  *
     14  * This library is distributed in the hope that it will be useful,
     15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17  * Library General Public License for more details.
     18  *
     19  * You should have received a copy of the GNU Library General Public License
     20  * along with this library; see the file COPYING.LIB.  If not, write to
     21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     22  * Boston, MA 02110-1301, USA.
     23  *
     24  */
     25 
     26 #include "config.h"
     27 #include "PopupMenu.h"
     28 
     29 #include "Chrome.h"
     30 #include "ChromeClientQt.h"
     31 #include "FrameView.h"
     32 #include "PopupMenuClient.h"
     33 #include "QWebPageClient.h"
     34 #include "QtAbstractWebPopup.h"
     35 
     36 namespace WebCore {
     37 
     38 PopupMenu::PopupMenu(PopupMenuClient* client)
     39     : m_popupClient(client)
     40     , m_popup(0)
     41 {
     42 }
     43 
     44 PopupMenu::~PopupMenu()
     45 {
     46     delete m_popup;
     47 }
     48 
     49 void PopupMenu::show(const IntRect& rect, FrameView* view, int index)
     50 {
     51     ChromeClientQt* chromeClient = static_cast<ChromeClientQt*>(
     52         view->frame()->page()->chrome()->client());
     53     ASSERT(chromeClient);
     54 
     55     if (!m_popup)
     56         m_popup = chromeClient->createSelectPopup();
     57 
     58     m_popup->m_popupClient = m_popupClient;
     59     m_popup->m_currentIndex = index;
     60     m_popup->m_pageClient = chromeClient->platformPageClient();
     61 
     62     QRect geometry(rect);
     63     geometry.moveTopLeft(view->contentsToWindow(rect.topLeft()));
     64     m_popup->m_geometry = geometry;
     65 
     66     m_popup->show();
     67 
     68 }
     69 
     70 void PopupMenu::hide()
     71 {
     72     m_popup->hide();
     73 }
     74 
     75 void PopupMenu::updateFromElement()
     76 {
     77     client()->setTextFromItem(m_popupClient->selectedIndex());
     78 }
     79 
     80 bool PopupMenu::itemWritingDirectionIsNatural()
     81 {
     82     return false;
     83 }
     84 
     85 }
     86 
     87 // vim: ts=4 sw=4 et
     88