ginebra2/UrlSearchSnippet.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 9 b39122337a00
--- a/ginebra2/UrlSearchSnippet.cpp	Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/UrlSearchSnippet.cpp	Tue Jun 29 00:46:29 2010 -0400
@@ -1,112 +1,57 @@
 /*
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
 *
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License for more details.
 *
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program.  If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
 *
-* Description: 
+* Description:
 *
 */
 
-
 #include "UrlSearchSnippet.h"
 #include "Utilities.h"
 
 #include "ChromeRenderer.h"
+#include "ChromeLayout.h"
 #include "ChromeWidget.h"
+#include "PageSnippet.h"
 #include "ViewController.h"
+#include "ViewStack.h"
 #include "WebChromeSnippet.h"
+#include "LoadController.h"
+#include "webpagecontroller.h"
+#include "GWebContentView.h"
+#include "WindowFlowView.h"
 
-#include "webpagecontroller.h"
+#include <QWebHistoryItem>
 
 namespace GVA {
 
-// Methods for class UrlEditorWidget
-
-UrlEditorWidget::UrlEditorWidget(QGraphicsItem * parent)
-: QGraphicsTextItem(parent)
-{
-    // Disable wrapping, force text to be stored and displayed
-    // as a single line.
-
-    QTextOption textOption = document()->defaultTextOption();
-    textOption.setWrapMode(QTextOption::NoWrap);
-    document()->setDefaultTextOption(textOption);
-
-    // Enable cursor keys.
-
-    setTextInteractionFlags(Qt::TextEditorInteraction);
-
-    // This is needed to initialize m_textLine.
-
-    setText("");
-}
-
-UrlEditorWidget::~UrlEditorWidget()
-{
-}
-
-void UrlEditorWidget::setText(const QString & text)
-{
-    setPlainText(text);
-    m_textLine = document()->begin().layout()->lineForTextPosition(0);
-}
+#define GO_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/go_btn.png"
+#define STOP_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/stop_btn.png"
+#define REFRESH_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/refresh_btn.png"
+#define BETWEEN_ENTRY_AND_BUTTON_SPACE 4
 
-qreal UrlEditorWidget::cursorX()
-{
-    return m_textLine.cursorToX(textCursor().position());
-}
-
-void UrlEditorWidget::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
-{
-    // Paint without ugly selection ants (the dashed line that surrounds
-    // the selected text).
-
-    QStyleOptionGraphicsItem newOption = *option;
-    newOption.state &= (!QStyle::State_Selected | !QStyle::State_HasFocus);
-
-    painter->save();
-
-    QGraphicsTextItem::paint(painter, &newOption, widget);
-
-    painter->restore();
-}
-
-void UrlEditorWidget::keyPressEvent(QKeyEvent * event)
-{
-    // Signal horizontal cursor movement so UrlSearchSnippet can
-    // implement horizontal scrolling.
-
-    qreal oldX = cursorX();
-
-    QGraphicsTextItem::keyPressEvent(event);
-
-    qreal newX = cursorX();
-
-    if (newX != oldX) {
-        emit cursorXChanged(newX);
-    }
-}
-
-// Methods for class UrlSearchSnippet
-
-UrlSearchSnippet::UrlSearchSnippet(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
+GUrlSearchItem::GUrlSearchItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
 : NativeChromeItem(snippet, parent)
 , m_chrome(chrome)
-, m_percent(0)
-, m_pendingClearCalls(0)
 , m_viewPortWidth(0.0)
 , m_viewPortHeight(0.0)
+, m_pendingClearCalls(0)
+, m_backFromNewWinTrans(false)
+, m_justFocusIn(false)
 {
-    setFlags(QGraphicsItem::ItemIsMovable);
-
     // Extract style information from element CSS.
 
     // For border-related properties, we constrain all values (top, left, etc.)
@@ -117,13 +62,20 @@
 
     QWebElement we = m_snippet->element();
 
+    QColor textColor;
     NativeChromeItem::CSSToQColor(
             we.styleProperty("color", QWebElement::ComputedStyle),
-            m_textColor);
+            textColor);
 
+    QColor backgroundColor;
     NativeChromeItem::CSSToQColor(
             we.styleProperty("background-color", QWebElement::ComputedStyle),
-            m_backgroundColor);
+            backgroundColor); // FIXME text edit background color doesn't work
+
+    QColor progressColor;
+    NativeChromeItem::CSSToQColor(
+            we.styleProperty("border-bottom-color", QWebElement::ComputedStyle),
+            progressColor); //FIXME text-underline-color causes the crash
 
     NativeChromeItem::CSSToQColor(
             we.styleProperty("border-top-color", QWebElement::ComputedStyle),
@@ -135,38 +87,52 @@
     QString cssBorder = we.styleProperty("border-top-width", QWebElement::ComputedStyle);
     m_border = cssBorder.remove("px").toInt();
 
-    // The viewport clips the editor when text overflows
-
+    // Create the view port widget
     m_viewPort = new QGraphicsWidget(this);
     m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
 
-    // The actual text editor item
+    // Create the url search editor
+    m_urlSearchEditor = new GProgressEditor(snippet, chrome, m_viewPort);
+    m_urlSearchEditor->setTextColor(textColor);
+    m_urlSearchEditor->setBackgroundColor(backgroundColor);
+    m_urlSearchEditor->setProgressColor(progressColor);
+    m_urlSearchEditor->setBorderColor(m_borderColor);
+    m_urlSearchEditor->setPadding(0.1); // draw the Rounded Rect
+    m_urlSearchEditor->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+    safe_connect(m_urlSearchEditor, SIGNAL(textMayChanged()), this, SLOT(updateLoadStateAndSuggest()));
+    safe_connect(m_urlSearchEditor, SIGNAL(activated()),this, SLOT(urlSearchActivatedByEnterKey()));
+    safe_connect(m_urlSearchEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool)));
+    safe_connect(m_urlSearchEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&)));
 
-    m_editor = new UrlEditorWidget(m_viewPort);
-    m_editor->setDefaultTextColor(m_textColor);
-    m_editor->installEventFilter(this);
+    // Create the url search button
+    m_urlSearchBtn = new ActionButton(snippet, m_viewPort);
+    QAction* urlSearchBtnAction = new QAction(this);
+    m_urlSearchBtn->setAction(urlSearchBtnAction); // FIXME: should use diff QActions
+
+    m_urlSearchBtn->setActiveOnPress(false);
+    safe_connect(urlSearchBtnAction, SIGNAL(triggered()), this, SLOT(urlSearchActivated()));
 
-    // Monitor editor cursor position changes for horizontal scrolling.
+    // Get the icon size
+    QIcon btnIcon(GO_BUTTON_ICON);
+    QSize defaultSize(50, 50);
+    QSize actualSize = btnIcon.actualSize(defaultSize);
+    m_iconWidth = actualSize.width();
+    m_iconHeight = actualSize.height();
+    // Set the right text margin to accomodate the icon inside the editor
+    m_urlSearchEditor->setRightTextMargin(m_iconWidth + BETWEEN_ENTRY_AND_BUTTON_SPACE);
 
-    safe_connect(m_editor, SIGNAL(cursorXChanged(qreal)),
-            this, SLOT(makeVisible(qreal)));
+    // Update state as soon as chrome completes loading.
+    safe_connect(m_chrome, SIGNAL(chromeComplete()),
+            this, SLOT(onChromeComplete()));
 
     // Monitor resize events.
-
     safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()),
             this, SLOT(resize()));
 
-    // Update state as soon as chrome completes loading.
-
-    safe_connect(m_chrome, SIGNAL(chromeComplete()),
-            this, SLOT(setStarted()));
-
-    // Monitor page loading.
-
     WebPageController * pageController = WebPageController::getSingleton();
 
     safe_connect(pageController, SIGNAL(pageUrlChanged(const QString)),
-            this, SLOT(setUrlText(const QString &)));
+            m_urlSearchEditor, SLOT(setText(const QString &)))
 
     safe_connect(pageController, SIGNAL(pageLoadStarted()),
             this, SLOT(setStarted()));
@@ -177,153 +143,139 @@
     safe_connect(pageController, SIGNAL(pageLoadFinished(bool)),
             this, SLOT(setFinished(bool)));
 
+    safe_connect(pageController, SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
+            this, SLOT(setPageCreated()));
+
+    safe_connect(pageController, SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
+            this, SLOT(setPageChanged()));
+
     // Monitor view changes.
 
     ViewController * viewController = chrome->viewController();
 
     safe_connect(viewController, SIGNAL(currentViewChanged()),
             this, SLOT(viewChanged()));
+
+ /*   safe_connect(ViewStack::getSingleton(), SIGNAL(currentViewChanged()),
+            this, SLOT(viewChanged()));*/
 }
 
-UrlSearchSnippet::~UrlSearchSnippet()
+GUrlSearchItem::~GUrlSearchItem()
 {
 }
 
-bool UrlSearchSnippet::eventFilter(QObject * object, QEvent * event)
+//TODO: Shouldn't have to explicitly set the viewport sizes here
+
+void GUrlSearchItem::resizeEvent(QGraphicsSceneResizeEvent * event)
 {
-    // Filter editor key events.
+    QSizeF size = event->newSize();
+
+    m_viewPortWidth  = size.width()  - m_padding * 2;
+    m_viewPortHeight = size.height() - m_padding * 2;
+    
+    m_viewPort->setGeometry(
+            m_padding,
+            m_padding,
+            m_viewPortWidth,
+            m_viewPortHeight);
+
+    qreal w = m_iconWidth;
+    qreal h = m_iconHeight;
+
+    m_urlSearchBtn->setGeometry(
+	    m_viewPortWidth - w - m_padding/2,
+	    (m_viewPortHeight - h)/2,
+	    w,
+	    h);
+
+    m_urlSearchEditor->setGeometry(0,
+            0,
+            m_viewPortWidth,
+            m_viewPortHeight);
+
+}
 
-    if (object != m_editor) {
-        return false;
-    }
+void GUrlSearchItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
+{
+    Q_UNUSED(option);
+    Q_UNUSED(widget);
+
+    painter->save();
+    painter->setRenderHint(QPainter::Antialiasing);
 
-    if (event->type() != QEvent::KeyPress) {
-        return false;
+    if (m_padding > 0 || m_border > 0) {
+        QPainterPath border;
+        border.addRect(boundingRect());
+        border.addRoundedRect(
+                m_padding,
+                m_padding,
+                m_viewPortWidth,
+                m_viewPortHeight,
+                4,
+                4);
+
+        if (m_padding > 0) {
+            painter->fillPath(border, m_borderColor);
+        }
+
+        if (m_border > 0) {
+            QPen pen;
+            pen.setWidth(m_border);
+            pen.setBrush(m_borderColor);
+            painter->setPen(pen);
+            painter->drawPath(border);
+        }
     }
 
-    QKeyEvent * keyEvent = static_cast<QKeyEvent*>(event);
+    painter->restore();
+    NativeChromeItem::paint(painter, option, widget);
+}
+
+void GUrlSearchItem::onChromeComplete()
+{
+    setStarted();
 
-    switch (keyEvent->key()) {
-    case Qt::Key_Select:
-    case Qt::Key_Return:
-    case Qt::Key_Enter:
-        // Signal that a carriage return-like key-press happened.
-        emit activated();
-        return true;
+    WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_chrome->viewController()->view("WindowView"));
+    safe_connect(windowView, SIGNAL(newWindowTransitionComplete()), this, SLOT(onNewWindowTransitionComplete()));
 
-    case Qt::Key_Down:
-    case Qt::Key_Up:
-        // Swallow arrow up/down keys, editor has just one line.
-        return true;
+    PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
 
-    default:
-        return false;
+    // instantiate items needed to display suggest page snippet
+    if (suggestSnippet) {
+        suggestSnippet->instantiate();
     }
 }
 
-void UrlSearchSnippet::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
+void GUrlSearchItem::setStarted()
 {
-    // Make sure any required horizontal scrolling happens
-    // before rendering UrlEditorWidget.
-
-    makeVisible(m_editor->cursorX());
-
-    NativeChromeItem::paint(painter, option,widget);
-
-    painter->save();
-
-    painter->setRenderHint(QPainter::Antialiasing);
-    painter->setBrush(m_backgroundColor);
-
-    // First, do progress bar.
-
-    QRectF g = boundingRect();
-    g.setWidth(g.width() * m_percent / 100.0);
-    painter->fillRect(g, QColor::fromRgb(0, 200, 200, 50));
-
-    // Next, background matte.
-
-    if (m_border > 0) {
-        QPen pen;
-        pen.setWidth(m_border);
-        pen.setBrush(m_borderColor);
-        painter->setPen(pen);
-    }
-
-    QPainterPath background;
-    background.addRect(boundingRect());
-    background.addRoundedRect(
-            m_padding,
-            m_padding,
-            m_viewPortWidth,
-            m_viewPortHeight,
-            4,
-            4);
-    painter->drawPath(background);
+    WebPageController * pageController = WebPageController::getSingleton();
+    ViewController * viewController = m_chrome->viewController();
 
-    painter->restore();
-}
-
-void UrlSearchSnippet::resizeEvent(QGraphicsSceneResizeEvent * event)
-{
-    QSizeF size = event->newSize();
-
-    m_viewPort->resize(size);
-
-    m_viewPortWidth  = size.width()  - m_padding * 2;
-    m_viewPortHeight = size.height() - m_padding * 2;
-
-    m_viewPort->setGeometry(
-            m_padding,
-            (size.height() - m_editor->boundingRect().height()) / 2,
-            m_viewPortWidth,
-            m_viewPortHeight);
-
-    m_editor->setTextWidth(m_viewPortWidth);
-}
-
-void UrlSearchSnippet::resize()
-{
-    QWebElement we = m_snippet->element();
-
-    QRectF g = we.geometry();
-
-    qreal newWidth  = g.width();
-
-    qreal newHeight = g.height();
-
-    QGraphicsWidget::resize(newWidth, newHeight);
-}
-
-void UrlSearchSnippet::setUrlText(const QString & text)
-{
-    m_editor->setText(text);
-    m_editor->setPos(0, m_editor->pos().y());
-
-    makeVisible(m_editor->cursorX());
-}
-
-void UrlSearchSnippet::setStarted()
-{
+    m_urlSearchEditor->setText(pageController->currentRequestedUrl());
+    ControllableViewBase* curView = viewController->currentView();
+    if (curView && curView->type() == "webView") {
+        GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
+        bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
+        if(!isSuperPage)
+	  m_chrome->layout()->slideView(100);
+    }
     // Strictly speaking we should set progress to 0.
     // But set it higher to give immediate visual feedback
     // that something is happening.
 
     int progress = 0;
 
-    WebPageController * pageController = WebPageController::getSingleton();
-
     if (pageController->isPageLoading()) {
         progress = 5;
     }
 
-    setProgress(progress);
+    m_urlSearchEditor->setProgress(progress);
+    updateUrlSearchBtn();
 }
 
-void UrlSearchSnippet::setProgress(int percent)
+void GUrlSearchItem::setProgress(int percent)
 {
-    m_percent = percent;
-    update();
+    m_urlSearchEditor->setProgress(percent);
 }
 
 // Wait a half-second before actually clearing the progress bar.
@@ -350,19 +302,47 @@
 //    appearance for the full timeout period.  We manage this by
 //    tracking the number of pending calls to clearProgress() and
 //    only clearing the progress bar when that number becomes 0.
-
-void UrlSearchSnippet::setFinished(bool ok)
+void GUrlSearchItem::setFinished(bool ok)
 {
-    if (ok) {
-        setProgress(99);
-    }
+    WebPageController * pageController = WebPageController::getSingleton();
+    // If the load was finished normally and not due to user stopping it,
+    // simulate progress completion
+    if (!pageController->loadCanceled())
+        m_urlSearchEditor->setProgress(100);
+
+    if (ok)
+        m_urlSearchEditor->setText(formattedUrl());
+
+    m_urlSearchEditor->removeFocus();
+
+    ViewController * viewController = m_chrome->viewController();
+    ControllableViewBase* curView = viewController->currentView();
+    if (curView && curView->type() == "webView" && pageController->contentsYPos() > 0)
+      m_chrome->layout()->slideView(-100);
 
     ++m_pendingClearCalls;
 
     QTimer::singleShot(500, this, SLOT(clearProgress()));
 }
 
-void UrlSearchSnippet::clearProgress()
+void GUrlSearchItem::setPageCreated()
+{
+    // remove slideview(100) since the new transition for the code-driven window
+    //m_chrome->layout()->slideView(100);
+}
+
+void GUrlSearchItem::setPageChanged()
+{
+    m_urlSearchEditor->setText(formattedUrl());
+    updateUrlSearchBtn();
+
+    WebPageController * pageController = WebPageController::getSingleton();
+    int progress = pageController->loadProgressValue();
+    if (progress == 100)
+        m_urlSearchEditor->removeFocus();
+}
+
+void GUrlSearchItem::clearProgress()
 {
     --m_pendingClearCalls;
 
@@ -371,75 +351,231 @@
     }
 
     WebPageController * pageController = WebPageController::getSingleton();
-
     if (pageController->isPageLoading()) {
         return;
     }
-
-    setProgress(0);
+    m_urlSearchEditor->setProgress(0);
+    updateUrlSearchBtn();
 }
 
-void UrlSearchSnippet::viewChanged()
+void GUrlSearchItem::viewChanged()
 {
+    ViewController * viewController = m_chrome->viewController();
     WebPageController * pageController = WebPageController::getSingleton();
 
-    setUrlText(pageController->currentDocUrl());
+    ControllableViewBase* curView = viewController->currentView();
+    GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
+    bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
+
+    // view changes to web content view
+    if (curView && curView->type() == "webView" && !isSuperPage) {
+        int progress = pageController->loadProgressValue();
+        if (progress >= 100)
+            progress = 0;
+        m_urlSearchEditor->setProgress(progress);
+        updateUrlSearchBtn();
+
+        // place focus in urlsearch bar when returning from adding a new window in windows view
+        if (pageController->loadText() == "") {
+            if (m_backFromNewWinTrans ) {
+                m_backFromNewWinTrans = false;
+                WebPageController * pageController = WebPageController::getSingleton();
+                m_urlSearchEditor->setText(pageController->currentRequestedUrl());
+            }
+            else {
+                m_urlSearchEditor->grabFocus();
+            }
+        }
+        if (!isSuperPage  && (pageController->contentsYPos() <= 0 || pageController->isPageLoading())){
+	  m_chrome->layout()->slideView(100);
+        } else {
+	  m_chrome->layout()->slideView(-100);
+        }
+        m_backFromNewWinTrans = false;
+    } else {
+         pageController->urlTextChanged(m_urlSearchEditor->text());
+         // Remove progress bar
+         // incorrect values are not seen before we can update when we come back
+         m_urlSearchEditor->setProgress(0);
+         m_chrome->layout()->slideView(-100);
+    }
+}
+
+void GUrlSearchItem::urlSearchActivatedByEnterKey()
+{
+    m_urlSearchEditor->removeFocus();
+    urlSearchActivated();
+}
 
-    int progress = pageController->loadProgressValue();
-    if (progress >= 100) {
-        progress = 0;
+void GUrlSearchItem::urlSearchActivated()
+{
+    WebPageController * pageController = WebPageController::getSingleton();
+    switch (pageController->loadState()) {
+        case WRT::LoadController::GotoModeLoading:
+            pageController->currentStop();
+            ++m_pendingClearCalls;
+            QTimer::singleShot(500, this, SLOT(clearProgress()));
+            break;
+        case WRT::LoadController::GotoModeEditing:
+            loadToMainWindow();
+            break;
+        case WRT::LoadController::GotoModeReloadable:
+            if (pageController->currentDocUrl() == m_urlSearchEditor->text())
+                pageController->currentReload();
+            else
+                loadToMainWindow();
+            break;
+        default:
+            qDebug() << "Incorrect state";
+            break;
     }
-    setProgress(progress);
+    updateUrlSearchBtn();
+}
+
+void GUrlSearchItem::updateUrlSearchBtn()
+{
+    WebPageController * pageController = WebPageController::getSingleton();
+    switch (pageController->loadState()) {
+        case WRT::LoadController::GotoModeLoading:
+            m_urlSearchBtn->addIcon(STOP_BUTTON_ICON);
+            break;
+        case WRT::LoadController::GotoModeEditing:
+            m_urlSearchBtn->addIcon(GO_BUTTON_ICON);
+            break;
+        case WRT::LoadController::GotoModeReloadable:
+            m_urlSearchBtn->addIcon(REFRESH_BUTTON_ICON);
+            break;
+        default:
+            qDebug() << "Incorrect state";
+            break;
+    }
+    m_urlSearchBtn->update();
+    
+    // notify suggest object of changes in load state
+    PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
+    if (suggestSnippet) {
+        QString cmd = "searchSuggests.updateLoadState();";
+        suggestSnippet->evaluateJavaScript(cmd);
+    }
 }
 
-// We divide the viewport into 3 distinct regions:
-//
-//
-//        [ left | middle | right ]
-//
-// [ editor, shifted left by editorShift pixels ]
-//
-// When a cursor is in the middle section of the viewport we
-// leave the editor shift unchanged, to preserve stability.
-//
-// When a cursor is in the right section or beyond we shift
-// the editor left until the cursor appears at the border
-// between the middle and right sections.
-//
-// When a cursor is in the left section or beyond we shift
-// the editor right until the cursor appears at the border
-// between the left and middle sections.
-//
-// We never shift the editor right of the viewport.
+void GUrlSearchItem::loadToMainWindow()
+{
+    QString url = m_urlSearchEditor->text();
+    WebPageController * pageController = WebPageController::getSingleton();
+    QString gotourl = pageController->guessUrlFromString(url);
+    m_urlSearchEditor->setText(gotourl);
+    pageController->currentLoad(gotourl);
+    pageController->urlTextChanged(gotourl);
+}
+
+void GUrlSearchItem::updateLoadState()
+{
+    WebPageController * pageController = WebPageController::getSingleton();
+    if (pageController->loadState() == WRT::LoadController::GotoModeReloadable) {
+        pageController->setLoadState(WRT::LoadController::GotoModeEditing);
+        updateUrlSearchBtn();
+    }
+}
 
-void UrlSearchSnippet::makeVisible(qreal cursorX)
+void GUrlSearchItem::updateLoadStateAndSuggest()
 {
-    qreal leftScrollBorder  = 0;
+    updateLoadState();
+    PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
+    if (suggestSnippet) {
+        QString cmd = "searchSuggests.updateUserInput();";
+        suggestSnippet->evaluateJavaScript(cmd);
+    }
+}
+
+void GUrlSearchItem::tapped(QPointF& pos)
+{
+    bool hitText = m_urlSearchEditor->tappedOnText(pos.x());
+    if (!m_justFocusIn && !hitText)
+        m_urlSearchEditor->unselect();
+
+    if (m_justFocusIn) {
+        m_justFocusIn = false;
+        if (hitText && !m_urlSearchEditor->hasSelection())
+            m_urlSearchEditor->selectAll();
+    }
+}
 
-    qreal rightScrollBorder = m_viewPortWidth - 10;
+void GUrlSearchItem::focusChanged(bool focusIn)
+{
+    if (focusIn)
+        m_justFocusIn = true;
+    else {
+        m_justFocusIn = false;
+        m_urlSearchEditor->unselect();
+        m_urlSearchEditor->shiftToLeftEnd();
+        
+        // Suggestion snippet needs to know about this event.
+        PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
+        if (suggestSnippet) {
+            QString cmd = "searchSuggests.urlSearchLostFocus();";
+            suggestSnippet->evaluateJavaScript(cmd);
+        }
+    }
+}
 
-    qreal editorShift = -1 * m_editor->pos().x();
+void GUrlSearchItem::resize()
+{
+    QWebElement we = m_snippet->element();
+    QRectF g = we.geometry();
+    qreal newWidth  = g.width();
+    qreal newHeight = g.height();
+    QGraphicsWidget::resize(newWidth, newHeight);
+}
 
-    qreal localX = cursorX - editorShift;
+void GUrlSearchItem::onNewWindowTransitionComplete()
+{
+    m_backFromNewWinTrans = true;
+}
 
-    if (localX < leftScrollBorder) {
-        // Before left section, scroll right.
-        // In left section, scroll right.
-        qreal shift = qMin(leftScrollBorder - localX, editorShift);
-        m_editor->moveBy(shift, 0);
-        return;
+QString GUrlSearchItem::formattedUrl() const
+{
+    WebPageController * pageController = WebPageController::getSingleton();
+    QString url = pageController->loadText();
+    // for first load of the windows restored from last session
+    if (url.isEmpty()&& pageController->currentDocUrl().isEmpty()) {
+        QWebHistoryItem item = pageController->currentPage()->history()->currentItem();
+        url = item.url().toString();
     }
+    return url.replace(" ","+");
+}
+
+GUrlSearchSnippet::GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome,
+                         QGraphicsWidget * widget, const QWebElement & element)
+  : ChromeSnippet(elementId, chrome, widget, element)
+{
+}
 
-    if (localX >= rightScrollBorder) {
-        // In right section, scroll left.
-        // After right section, scroll left.
-        qreal shift = localX - rightScrollBorder;
-        m_editor->moveBy(-shift, 0);
-        return;
-    }
+GUrlSearchSnippet * GUrlSearchSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
+{
+    GUrlSearchSnippet* that = new GUrlSearchSnippet(elementId, chrome, 0, element);
+    that->setChromeWidget( new GUrlSearchItem( that, chrome ) );
+    return that;
+}
+
+inline GUrlSearchItem* GUrlSearchSnippet::urlSearchItem()
+{
+    return static_cast<GUrlSearchItem *>(widget());
+}
 
-    // In middle section, no scroll needed.
-    return;
+inline GUrlSearchItem const * GUrlSearchSnippet::constUrlSearchItem() const
+{
+    return static_cast<GUrlSearchItem const *>(constWidget());
+}
+
+QString GUrlSearchSnippet::url() const
+{
+    return constUrlSearchItem()->url();
+}
+
+void GUrlSearchSnippet::setUrl(const QString &url)
+{
+    urlSearchItem()->setUrl(url);
 }
 
 } // namespace GVA