ginebra2/UrlSearchSnippet.cpp
changeset 12 afcd8e6d025b
parent 9 b39122337a00
child 14 6aeb7a756187
equal deleted inserted replaced
11:786160610b4d 12:afcd8e6d025b
    32 #include "LoadController.h"
    32 #include "LoadController.h"
    33 #include "webpagecontroller.h"
    33 #include "webpagecontroller.h"
    34 #include "GWebContentView.h"
    34 #include "GWebContentView.h"
    35 #include "WindowFlowView.h"
    35 #include "WindowFlowView.h"
    36 
    36 
       
    37 
    37 #include <QWebHistoryItem>
    38 #include <QWebHistoryItem>
    38 
    39 
    39 namespace GVA {
    40 namespace GVA {
    40 
    41 
    41 #define GO_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/go_btn.png"
    42 #define GO_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/go_btn.png"
    42 #define STOP_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/stop_btn.png"
    43 #define STOP_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/stop_btn.png"
    43 #define REFRESH_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/refresh_btn.png"
    44 #define REFRESH_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/refresh_btn.png"
    44 #define SPECIFIC_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/com.svg"
    45 #define SPECIFIC_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/com.svg"
    45 #define SPECIFIC_BUTTON_STRING ".com"
    46 #define SPECIFIC_BUTTON_STRING ".com"
    46 #define BETWEEN_ENTRY_AND_BUTTON_SPACE 4
    47 #define BETWEEN_ENTRY_AND_BUTTON_SPACE 4
       
    48 
       
    49 static const QString KBookmarkHistoryViewName = "BookmarkHistoryView";
       
    50 static const QString KBookmarkTreeViewName = "BookmarkTreeView";
       
    51 static const QString KWindowViewName = "WindowView";
       
    52 static const QString KSettingsViewName = "SettingsView";
       
    53 
       
    54 //#define VBORDER_GRADIENT_START "#292929"
       
    55 //#define VBORDER_GRADIENT_STOP "#535354"
       
    56 //#define VBORDER_GRADIENT_END "#020202"
    47 
    57 
    48 GUrlSearchItem::GUrlSearchItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
    58 GUrlSearchItem::GUrlSearchItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
    49 : NativeChromeItem(snippet, parent)
    59 : NativeChromeItem(snippet, parent)
    50 , m_chrome(chrome)
    60 , m_chrome(chrome)
    51 , m_viewPortWidth(0.0)
    61 , m_viewPortWidth(0.0)
    60     // to be the same.  These can be set using the css shorthand (e.g. padding:10px),
    70     // to be the same.  These can be set using the css shorthand (e.g. padding:10px),
    61     // but the computed css style will be for the four primitive values (padding-top,
    71     // but the computed css style will be for the four primitive values (padding-top,
    62     // padding-left) etc, which will all be equal.  Hence we just use one of the
    72     // padding-left) etc, which will all be equal.  Hence we just use one of the
    63     // computed primitive values (top) to represent the common value.
    73     // computed primitive values (top) to represent the common value.
    64 
    74 
       
    75 
    65     QWebElement we = m_snippet->element();
    76     QWebElement we = m_snippet->element();
    66 
    77 
    67     QColor textColor;
    78     QColor textColor;
       
    79 
       
    80     QColor backgroundColor;
       
    81     QColor progressColor;
       
    82 
       
    83 #ifndef BROWSER_LAYOUT_TENONE
       
    84 
    68     NativeChromeItem::CSSToQColor(
    85     NativeChromeItem::CSSToQColor(
    69             we.styleProperty("color", QWebElement::ComputedStyle),
    86             we.styleProperty("color", QWebElement::ComputedStyle),
    70             textColor);
    87             textColor);
    71 
    88 
    72     QColor backgroundColor;
       
    73     NativeChromeItem::CSSToQColor(
    89     NativeChromeItem::CSSToQColor(
    74             we.styleProperty("background-color", QWebElement::ComputedStyle),
    90             we.styleProperty("background-color", QWebElement::ComputedStyle),
    75             backgroundColor); // FIXME text edit background color doesn't work
    91             backgroundColor);
    76 
       
    77     QColor progressColor;
       
    78     NativeChromeItem::CSSToQColor(
       
    79             we.styleProperty("border-bottom-color", QWebElement::ComputedStyle),
       
    80             progressColor); //FIXME text-underline-color causes the crash
       
    81 
    92 
    82     NativeChromeItem::CSSToQColor(
    93     NativeChromeItem::CSSToQColor(
    83             we.styleProperty("border-top-color", QWebElement::ComputedStyle),
    94             we.styleProperty("border-top-color", QWebElement::ComputedStyle),
    84             m_borderColor);
    95             m_borderColor);
    85 
    96 #endif
       
    97 
       
    98     NativeChromeItem::CSSToQColor(
       
    99             we.styleProperty("border-bottom-color", QWebElement::ComputedStyle),
       
   100             progressColor);
       
   101             
       
   102 #ifdef BROWSER_LAYOUT_TENONE
       
   103     QFont titleFont;
       
   104     QColor titleColor;
       
   105     textColor = QColor(Qt::black);
       
   106     titleColor = QColor(Qt::white);
       
   107     m_borderColor = QColor(Qt::transparent);
       
   108     backgroundColor = QColor(Qt::transparent);
       
   109     
       
   110     titleFont = QFont(QApplication::font());
       
   111     titleFont.setPointSize(9);
       
   112     titleFont.setWeight(QFont::Bold);
       
   113 #endif
       
   114  
    86     QString cssPadding = we.styleProperty("padding-top", QWebElement::ComputedStyle);
   115     QString cssPadding = we.styleProperty("padding-top", QWebElement::ComputedStyle);
    87     m_padding = cssPadding.remove("px").toInt();
   116     m_padding = cssPadding.remove("px").toInt();
    88 
   117 
    89     QString cssBorder = we.styleProperty("border-top-width", QWebElement::ComputedStyle);
   118     QString cssBorder = we.styleProperty("border-top-width", QWebElement::ComputedStyle);
    90     m_border = cssBorder.remove("px").toInt();
   119     m_border = cssBorder.remove("px").toInt();
    94     m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
   123     m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
    95 
   124 
    96     // Create the url search editor
   125     // Create the url search editor
    97     m_urlSearchEditor = new GProgressEditor(snippet, chrome, m_viewPort);
   126     m_urlSearchEditor = new GProgressEditor(snippet, chrome, m_viewPort);
    98     m_urlSearchEditor->setTextColor(textColor);
   127     m_urlSearchEditor->setTextColor(textColor);
       
   128  #ifdef BROWSER_LAYOUT_TENONE
       
   129     m_urlSearchEditor->setTitleFont(titleFont);
       
   130     m_urlSearchEditor->setTitleColor(titleColor);
       
   131  #endif
    99     m_urlSearchEditor->setBackgroundColor(backgroundColor);
   132     m_urlSearchEditor->setBackgroundColor(backgroundColor);
   100     m_urlSearchEditor->setProgressColor(progressColor);
   133     m_urlSearchEditor->setProgressColor(progressColor);
   101     m_urlSearchEditor->setBorderColor(m_borderColor);
   134     m_urlSearchEditor->setBorderColor(m_borderColor);
   102     m_urlSearchEditor->setPadding(0.1); // draw the Rounded Rect
   135     m_urlSearchEditor->setPadding(0.1); // draw the Rounded Rect
   103     m_urlSearchEditor->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
   136     m_urlSearchEditor->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
   104     m_urlSearchEditor->setSpecificButton(SPECIFIC_BUTTON_STRING, SPECIFIC_BUTTON_ICON);
   137     m_urlSearchEditor->setSpecificButton(SPECIFIC_BUTTON_STRING, SPECIFIC_BUTTON_ICON);
   105     safe_connect(m_urlSearchEditor, SIGNAL(textMayChanged()), this, SLOT(updateLoadStateAndSuggest()));
   138     safe_connect(m_urlSearchEditor, SIGNAL(contentsChange(int, int, int)), 
       
   139         this, SLOT(updateLoadStateAndSuggest(int, int, int)));
   106     safe_connect(m_urlSearchEditor, SIGNAL(activated()),this, SLOT(urlSearchActivatedByEnterKey()));
   140     safe_connect(m_urlSearchEditor, SIGNAL(activated()),this, SLOT(urlSearchActivatedByEnterKey()));
   107     safe_connect(m_urlSearchEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool)));
   141     safe_connect(m_urlSearchEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool)));
   108     safe_connect(m_urlSearchEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&)));
   142     safe_connect(m_urlSearchEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&)));
       
   143 #ifdef BROWSER_LAYOUT_TENONE
       
   144     safe_connect(m_urlSearchEditor, SIGNAL(titleMouseEvent(QPointF&)),this, SLOT(changeToUrl(QPointF&)));
       
   145 #endif
   109 
   146 
   110     // Create the url search button
   147     // Create the url search button
   111     m_urlSearchBtn = new ActionButton(snippet, m_viewPort);
   148     m_urlSearchBtn = new ActionButton(snippet, m_viewPort);
   112     QAction* urlSearchBtnAction = new QAction(this);
   149     QAction* urlSearchBtnAction = new QAction(this);
   113     m_urlSearchBtn->setAction(urlSearchBtnAction); // FIXME: should use diff QActions
   150     m_urlSearchBtn->setAction(urlSearchBtnAction); // FIXME: should use diff QActions
   119     QIcon btnIcon(GO_BUTTON_ICON);
   156     QIcon btnIcon(GO_BUTTON_ICON);
   120     QSize defaultSize(50, 50);
   157     QSize defaultSize(50, 50);
   121     QSize actualSize = btnIcon.actualSize(defaultSize);
   158     QSize actualSize = btnIcon.actualSize(defaultSize);
   122     m_iconWidth = actualSize.width();
   159     m_iconWidth = actualSize.width();
   123     m_iconHeight = actualSize.height();
   160     m_iconHeight = actualSize.height();
       
   161     
   124     // Set the right text margin to accomodate the icon inside the editor
   162     // Set the right text margin to accomodate the icon inside the editor
   125     m_urlSearchEditor->setRightTextMargin(m_iconWidth + BETWEEN_ENTRY_AND_BUTTON_SPACE);
   163     m_urlSearchEditor->setRightTextMargin(m_iconWidth + BETWEEN_ENTRY_AND_BUTTON_SPACE);
   126 
   164 
   127     // Update state as soon as chrome completes loading.
   165     // Update state as soon as chrome completes loading.
   128     safe_connect(m_chrome, SIGNAL(chromeComplete()),
   166     safe_connect(m_chrome, SIGNAL(chromeComplete()),
   129             this, SLOT(onChromeComplete()));
   167             this, SLOT(onChromeComplete()));
   130 
   168 
       
   169 #ifndef BROWSER_LAYOUT_TENONE
   131     // Monitor resize events.
   170     // Monitor resize events.
   132     safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()),
   171     safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()),
   133             this, SLOT(resize()));
   172             this, SLOT(resize())); 
   134 
   173 #endif
   135     WebPageController * pageController = WebPageController::getSingleton();
       
   136 
       
   137     safe_connect(pageController, SIGNAL(pageUrlChanged(const QString)),
       
   138             m_urlSearchEditor, SLOT(setText(const QString &)))
       
   139 
       
   140     safe_connect(pageController, SIGNAL(pageLoadStarted()),
       
   141             this, SLOT(setStarted()));
       
   142 
       
   143     safe_connect(pageController, SIGNAL(pageLoadProgress(const int)),
       
   144             this, SLOT(setProgress(int)));
       
   145 
       
   146     safe_connect(pageController, SIGNAL(pageLoadFinished(bool)),
       
   147             this, SLOT(setFinished(bool)));
       
   148 
       
   149     safe_connect(pageController, SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
       
   150             this, SLOT(setPageCreated()));
       
   151 
       
   152     safe_connect(pageController, SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
       
   153             this, SLOT(setPageChanged()));
       
   154 
       
   155     // Monitor view changes.
       
   156 
       
   157     ViewController * viewController = chrome->viewController();
       
   158 
       
   159     safe_connect(viewController, SIGNAL(currentViewChanged()),
       
   160             this, SLOT(viewChanged()));
       
   161 
   174 
   162  /*   safe_connect(ViewStack::getSingleton(), SIGNAL(currentViewChanged()),
   175  /*   safe_connect(ViewStack::getSingleton(), SIGNAL(currentViewChanged()),
   163             this, SLOT(viewChanged()));*/
   176             this, SLOT(viewChanged()));*/
       
   177 
   164 }
   178 }
   165 
   179 
   166 GUrlSearchItem::~GUrlSearchItem()
   180 GUrlSearchItem::~GUrlSearchItem()
   167 {
   181 {
       
   182 
   168 }
   183 }
   169 
   184 
   170 //TODO: Shouldn't have to explicitly set the viewport sizes here
   185 //TODO: Shouldn't have to explicitly set the viewport sizes here
   171 
   186 
   172 void GUrlSearchItem::resizeEvent(QGraphicsSceneResizeEvent * event)
   187 void GUrlSearchItem::resizeEvent(QGraphicsSceneResizeEvent * event)
   174     QSizeF size = event->newSize();
   189     QSizeF size = event->newSize();
   175 
   190 
   176     m_viewPortWidth  = size.width()  - m_padding * 2;
   191     m_viewPortWidth  = size.width()  - m_padding * 2;
   177     m_viewPortHeight = size.height() - m_padding * 2;
   192     m_viewPortHeight = size.height() - m_padding * 2;
   178     
   193     
       
   194    
   179     m_viewPort->setGeometry(
   195     m_viewPort->setGeometry(
   180             m_padding,
   196             m_padding,
   181             m_padding,
   197             m_padding,
   182             m_viewPortWidth,
   198             m_viewPortWidth,
   183             m_viewPortHeight);
   199             m_viewPortHeight);
   193 
   209 
   194     m_urlSearchEditor->setGeometry(0,
   210     m_urlSearchEditor->setGeometry(0,
   195             0,
   211             0,
   196             m_viewPortWidth,
   212             m_viewPortWidth,
   197             m_viewPortHeight);
   213             m_viewPortHeight);
   198 
       
   199 }
   214 }
   200 
   215 
   201 void GUrlSearchItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
   216 void GUrlSearchItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
   202 {
   217 {
   203     Q_UNUSED(option);
   218     Q_UNUSED(option);
   230         }
   245         }
   231     }
   246     }
   232 
   247 
   233     painter->restore();
   248     painter->restore();
   234     NativeChromeItem::paint(painter, option, widget);
   249     NativeChromeItem::paint(painter, option, widget);
       
   250 
       
   251 }
       
   252 
       
   253 #ifdef BROWSER_LAYOUT_TENONE
       
   254 void GUrlSearchItem::changeToUrl(QPointF& pos)
       
   255 {
       
   256     ViewController * viewController = m_chrome->viewController();
       
   257 	ControllableViewBase* curView = viewController->currentView();
       
   258 
       
   259 	if( curView && curView->type() == "webView" ) {
       
   260         emit changeEditMode(true);
       
   261         //qDebug() << "GUrlSearchItem::changeToUrl";
       
   262         m_urlSearchEditor->changeEditorMode(true);
       
   263         m_urlSearchBtn->show();
       
   264         m_urlSearchEditor->grabFocus();
       
   265         tapped(pos);
       
   266         m_urlSearchEditor->openVKB();
       
   267 	}
       
   268 
       
   269 }
       
   270 
       
   271 void GUrlSearchItem::changeToTitle()
       
   272 {
       
   273     emit changeEditMode(false);
       
   274     m_urlSearchEditor->changeEditorMode(false);
       
   275     m_urlSearchBtn->hide();
       
   276 }
       
   277 
       
   278 #endif
       
   279 
       
   280 void GUrlSearchItem::onContentMouseEvent(QEvent::Type type )
       
   281 {
       
   282 
       
   283     //qDebug() << "UrlSearchItem::onContentMouseEvent" << type;
       
   284     // We are dismissing the VKB on mouse release so that if the mouse press was on a link
       
   285     // we will not close VKB that might cause a shift in geometry which can potentially prevent
       
   286     // the link from being selected
       
   287     if ((WebPageController::getSingleton()->editMode()) && (type == QEvent::GraphicsSceneMouseRelease)) {
       
   288         // Edit canceled, so update LoadController state
       
   289         changeLoadState(false);
       
   290     
       
   291         m_urlSearchEditor->closeVKB();
       
   292 
       
   293 #ifdef BROWSER_LAYOUT_TENONE
       
   294         if (! WebPageController::getSingleton()->isPageLoading())
       
   295             changeToTitle();
       
   296         // Set the text to the url of page
       
   297         setUrlText(urlToBeDisplayed());
       
   298 #endif
       
   299     }
       
   300     
   235 }
   301 }
   236 
   302 
   237 void GUrlSearchItem::onChromeComplete()
   303 void GUrlSearchItem::onChromeComplete()
   238 {
   304 {
       
   305     WebPageController * pageController = WebPageController::getSingleton();
       
   306 
       
   307     safe_connect(pageController, SIGNAL(pageUrlChanged(const QString)),
       
   308             this, SLOT(setUrlText(const QString &)))
       
   309 
       
   310     safe_connect(pageController, SIGNAL(pageLoadStarted()),
       
   311             this, SLOT(setStarted()));
       
   312 
       
   313     safe_connect(pageController, SIGNAL(pageLoadProgress(const int)),
       
   314             this, SLOT(setProgress(int)));
       
   315 
       
   316     safe_connect(pageController, SIGNAL(pageLoadFinished(bool)),
       
   317             this, SLOT(setFinished(bool)));
       
   318 
       
   319     safe_connect(pageController, SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
       
   320             this, SLOT(setPageCreated()));
       
   321 
       
   322     safe_connect(pageController, SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
       
   323             this, SLOT(setPageChanged()));
       
   324 
       
   325     safe_connect(pageController, SIGNAL(pageLoadFailed()),
       
   326             this, SLOT(setPageFailed()));
       
   327 #ifdef BROWSER_LAYOUT_TENONE
       
   328 	safe_connect(pageController, SIGNAL(titleChanged(const QString&)),
       
   329 		    this, SLOT(onTitleChange(const QString&)));
       
   330 #endif
       
   331     // Monitor view changes.
       
   332 
       
   333     ViewController * viewController = m_chrome->viewController();
       
   334 
       
   335     safe_connect(viewController, SIGNAL(currentViewChanged()),
       
   336             this, SLOT(viewChanged()));
       
   337 
       
   338 
       
   339     GWebContentView* webView = static_cast<GWebContentView*> (m_chrome->getView("WebView"));
       
   340     safe_connect(webView, SIGNAL(contentViewMouseEvent(QEvent::Type )), this, SLOT(onContentMouseEvent(QEvent::Type )));
       
   341 
       
   342 
   239     setStarted();
   343     setStarted();
   240 
   344 
   241     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_chrome->viewController()->view("WindowView"));
   345     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_chrome->viewController()->view("WindowView"));
   242     safe_connect(windowView, SIGNAL(newWindowTransitionComplete()), this, SLOT(onNewWindowTransitionComplete()));
   346     safe_connect(windowView, SIGNAL(newWindowTransitionComplete()), this, SLOT(onNewWindowTransitionComplete()));
   243 
   347 
   252 void GUrlSearchItem::setStarted()
   356 void GUrlSearchItem::setStarted()
   253 {
   357 {
   254     WebPageController * pageController = WebPageController::getSingleton();
   358     WebPageController * pageController = WebPageController::getSingleton();
   255     ViewController * viewController = m_chrome->viewController();
   359     ViewController * viewController = m_chrome->viewController();
   256 
   360 
   257     m_urlSearchEditor->setText(pageController->currentRequestedUrl());
   361 #ifdef BROWSER_LAYOUT_TENONE
       
   362     emit changeEditMode(false);
       
   363     m_urlSearchBtn->show();
       
   364     m_urlSearchEditor->changeEditorMode(true);
       
   365 #endif
       
   366 
       
   367     QString url = pageController->currentRequestedUrl();
       
   368     if(!url.contains(KBOOKMARKURLFILESLASH)){
       
   369        if(url.contains(KBOOKMARKURLFILE))
       
   370           url.replace(QString(KBOOKMARKURLFILE), QString(KBOOKMARKURLFILESLASH));
       
   371     }
       
   372     setUrlText(url);
   258     ControllableViewBase* curView = viewController->currentView();
   373     ControllableViewBase* curView = viewController->currentView();
   259     if (curView && curView->type() == "webView") {
   374     if (curView && curView->type() == "webView") {
   260         GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   375         GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   261         bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   376         bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   262         if(!isSuperPage)
   377         if(!isSuperPage)
   263 	  m_chrome->layout()->slideView(100);
   378           m_chrome->layout()->slideView(100);
   264     }
   379     }
   265     // Strictly speaking we should set progress to 0.
   380     // Strictly speaking we should set progress to 0.
   266     // But set it higher to give immediate visual feedback
   381     // But set it higher to give immediate visual feedback
   267     // that something is happening.
   382     // that something is happening.
   268 
   383 
   276     updateUrlSearchBtn();
   391     updateUrlSearchBtn();
   277 }
   392 }
   278 
   393 
   279 void GUrlSearchItem::setProgress(int percent)
   394 void GUrlSearchItem::setProgress(int percent)
   280 {
   395 {
   281     m_urlSearchEditor->setProgress(percent);
   396 	ViewController * viewController = m_chrome->viewController();
       
   397 	ControllableViewBase* curView = viewController->currentView();
       
   398 	if ( curView && curView->type() == "webView" )
       
   399 		m_urlSearchEditor->setProgress(percent);
   282 }
   400 }
   283 
   401 
   284 // Wait a half-second before actually clearing the progress bar.
   402 // Wait a half-second before actually clearing the progress bar.
   285 //
   403 //
   286 // We have to be careful of the following two use cases:
   404 // We have to be careful of the following two use cases:
   306 //    tracking the number of pending calls to clearProgress() and
   424 //    tracking the number of pending calls to clearProgress() and
   307 //    only clearing the progress bar when that number becomes 0.
   425 //    only clearing the progress bar when that number becomes 0.
   308 void GUrlSearchItem::setFinished(bool ok)
   426 void GUrlSearchItem::setFinished(bool ok)
   309 {
   427 {
   310     WebPageController * pageController = WebPageController::getSingleton();
   428     WebPageController * pageController = WebPageController::getSingleton();
       
   429     ViewController * viewController = m_chrome->viewController();
       
   430 	  ControllableViewBase* curView = viewController->currentView();
       
   431     //qDebug() << "GUrlSearchItem::setFinished" << pageController->loadState();
       
   432     
       
   433     if (pageController->loadState() != WRT::LoadController::GotoModeEditing) {
       
   434         m_urlSearchEditor->removeFocus();
       
   435         
       
   436         if ( ok && curView && curView->type() == "webView" ){
       
   437             setUrlText(formattedUrl());
       
   438 #ifdef BROWSER_LAYOUT_TENONE
       
   439             m_urlSearchEditor->setTitle(currentTitle());
       
   440 #endif
       
   441         }
       
   442         if (curView && curView->type() == "webView" && pageController->contentsYPos() > 0)
       
   443           m_chrome->layout()->slideView(-100);
       
   444     }
       
   445     
   311     // If the load was finished normally and not due to user stopping it,
   446     // If the load was finished normally and not due to user stopping it,
   312     // simulate progress completion
   447     // simulate progress completion
   313     if (!pageController->loadCanceled())
   448     if ( !pageController->loadCanceled() && curView && curView->type() == "webView" )
   314         m_urlSearchEditor->setProgress(100);
   449         m_urlSearchEditor->setProgress(100);
   315 
   450 
   316     if (ok)
   451     ++m_pendingClearCalls;
   317         m_urlSearchEditor->setText(formattedUrl());
   452 
   318 
   453     QTimer::singleShot(500, this, SLOT(clearProgress()));
   319     m_urlSearchEditor->removeFocus();
   454 }
   320 
   455 
       
   456 void GUrlSearchItem::setPageFailed()
       
   457 {
       
   458     WebPageController * pageController = WebPageController::getSingleton();
       
   459    	LoadController * loadController = pageController->currentPage()->loadController();
       
   460     if( loadController->loadCanceled() && !loadController->pointOfNoReturn() )
       
   461     {     
       
   462        setUrlText(loadController->urlText());
       
   463     }
       
   464     else
       
   465     {
       
   466    	   setUrlText(formattedUrl());
       
   467    	}
       
   468 }
       
   469 void GUrlSearchItem::setPageCreated()
       
   470 {
       
   471     // remove slideview(100) since the new transition for the code-driven window
       
   472     //m_chrome->layout()->slideView(100);
       
   473 }
       
   474 
       
   475 void GUrlSearchItem::setPageChanged()
       
   476 {
       
   477     setUrlText(formattedUrl());
       
   478     updateUrlSearchBtn();
       
   479     WebPageController * pageController = WebPageController::getSingleton();
       
   480 #ifdef BROWSER_LAYOUT_TENONE
       
   481     
   321     ViewController * viewController = m_chrome->viewController();
   482     ViewController * viewController = m_chrome->viewController();
   322     ControllableViewBase* curView = viewController->currentView();
   483     ControllableViewBase* curView = viewController->currentView();
   323     if (curView && curView->type() == "webView" && pageController->contentsYPos() > 0)
   484 
   324       m_chrome->layout()->slideView(-100);
   485     QString title;
   325 
   486     if (curView && curView->type() == KWindowViewName  ) {
   326     ++m_pendingClearCalls;
   487         title = getWindowsViewTitle();
   327 
   488     }
   328     QTimer::singleShot(500, this, SLOT(clearProgress()));
   489     else {
   329 }
   490    	    title = currentTitle();
   330 
   491     }
   331 void GUrlSearchItem::setPageCreated()
   492 
   332 {
   493     m_urlSearchEditor->setTitle(title);
   333     // remove slideview(100) since the new transition for the code-driven window
   494 #endif
   334     //m_chrome->layout()->slideView(100);
   495 
   335 }
   496 
   336 
       
   337 void GUrlSearchItem::setPageChanged()
       
   338 {
       
   339     m_urlSearchEditor->setText(formattedUrl());
       
   340     updateUrlSearchBtn();
       
   341 
       
   342     WebPageController * pageController = WebPageController::getSingleton();
       
   343     int progress = pageController->loadProgressValue();
   497     int progress = pageController->loadProgressValue();
   344     if (progress == 100)
   498     if (progress == 100)
   345         m_urlSearchEditor->removeFocus();
   499         m_urlSearchEditor->removeFocus();
   346 }
   500 }
   347 
   501 
   355 
   509 
   356     WebPageController * pageController = WebPageController::getSingleton();
   510     WebPageController * pageController = WebPageController::getSingleton();
   357     if (pageController->isPageLoading()) {
   511     if (pageController->isPageLoading()) {
   358         return;
   512         return;
   359     }
   513     }
       
   514 
   360     m_urlSearchEditor->setProgress(0);
   515     m_urlSearchEditor->setProgress(0);
   361     updateUrlSearchBtn();
   516     updateUrlSearchBtn();
       
   517     
       
   518 #ifdef BROWSER_LAYOUT_TENONE
       
   519     if ( !pageController->editMode() ) {
       
   520         changeToTitle();
       
   521     }
       
   522 #endif
   362 }
   523 }
   363 
   524 
   364 void GUrlSearchItem::viewChanged()
   525 void GUrlSearchItem::viewChanged()
   365 {
   526 {
   366     ViewController * viewController = m_chrome->viewController();
   527     ViewController * viewController = m_chrome->viewController();
   368 
   529 
   369     ControllableViewBase* curView = viewController->currentView();
   530     ControllableViewBase* curView = viewController->currentView();
   370     GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   531     GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   371     bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   532     bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   372 
   533 
       
   534 
   373     // view changes to web content view
   535     // view changes to web content view
   374     if (curView && curView->type() == "webView" && !isSuperPage) {
   536     if (curView && curView->type() == "webView" && !isSuperPage) {
   375         int progress = pageController->loadProgressValue();
   537         
   376         if (progress >= 100)
   538      
   377             progress = 0;
   539 #ifdef BROWSER_LAYOUT_TENONE
   378         m_urlSearchEditor->setProgress(progress);
   540 
   379         updateUrlSearchBtn();
   541         if (pageController->isPageLoading()) {
   380 
   542             m_urlSearchEditor->changeEditorMode(true);
   381         // place focus in urlsearch bar when returning from adding a new window in windows view
   543             m_urlSearchBtn->show();
   382         if (pageController->loadText() == "") {
   544 #endif
   383             if (m_backFromNewWinTrans ) {
   545             int progress = pageController->loadProgressValue();
   384                 m_backFromNewWinTrans = false;
   546             if (progress >= 100)
   385                 WebPageController * pageController = WebPageController::getSingleton();
   547                 progress = 0;
   386                 m_urlSearchEditor->setText(pageController->currentRequestedUrl());
   548             m_urlSearchEditor->setProgress(progress);
       
   549             updateUrlSearchBtn();
       
   550 
       
   551             // place focus in urlsearch bar when returning from adding a new window in windows view
       
   552             if (pageController->loadText() == "") {
       
   553                 if (m_backFromNewWinTrans ) {
       
   554                     m_backFromNewWinTrans = false;
       
   555                     setUrlText(pageController->currentRequestedUrl());
       
   556                 }
       
   557                 else {
       
   558                     m_urlSearchEditor->grabFocus();
       
   559                 }
   387             }
   560             }
   388             else {
   561 #ifdef BROWSER_LAYOUT_TENONE
   389                 m_urlSearchEditor->grabFocus();
       
   390             }
       
   391         }
   562         }
       
   563         else {
       
   564             m_urlSearchEditor->setTitle(currentTitle());
       
   565         }
       
   566 #endif
   392         if (!isSuperPage  && (pageController->contentsYPos() <= 0 || pageController->isPageLoading())){
   567         if (!isSuperPage  && (pageController->contentsYPos() <= 0 || pageController->isPageLoading())){
   393 	  m_chrome->layout()->slideView(100);
   568             m_chrome->layout()->slideView(100);
   394         } else {
   569         } else {
   395 	  m_chrome->layout()->slideView(-100);
   570             m_chrome->layout()->slideView(-100);
   396         }
   571         }
   397         m_backFromNewWinTrans = false;
   572         m_backFromNewWinTrans = false;
   398     } else {
   573     } else {
   399          pageController->urlTextChanged(m_urlSearchEditor->text());
   574 
   400          // Remove progress bar
   575      pageController->urlTextChanged(m_urlSearchEditor->text());
   401          // incorrect values are not seen before we can update when we come back
   576      // Remove progress bar
   402          m_urlSearchEditor->setProgress(0);
   577      // incorrect values are not seen before we can update when we come back
   403          m_chrome->layout()->slideView(-100);
   578      m_urlSearchEditor->setProgress(0);
   404     }
   579 
   405 }
   580 #ifdef BROWSER_LAYOUT_TENONE
       
   581      QString key = curView->objectName();
       
   582      if (key == KWindowViewName) {
       
   583          key = getWindowsViewTitle();
       
   584      }
       
   585      else if (key == KSettingsViewName) {
       
   586          key = qtTrId("txt_browser_settings_settings");
       
   587      }
       
   588      else if (key == KBookmarkHistoryViewName) {
       
   589          key = qtTrId("txt_browser_history_history");
       
   590      }
       
   591      else if (key == KBookmarkTreeViewName) {
       
   592          key = qtTrId("txt_browser_bookmarks_bookmarks");
       
   593      }
       
   594      changeToTitle();
       
   595      m_urlSearchEditor->setTitle(key);
       
   596 #else
       
   597      m_chrome->layout()->slideView(-100);
       
   598 #endif 
       
   599     }
       
   600 
       
   601 }
       
   602 
       
   603 #ifdef BROWSER_LAYOUT_TENONE
       
   604 void GUrlSearchItem::onTitleChange(const QString& text)
       
   605 {
       
   606 	ViewController * viewController = m_chrome->viewController();
       
   607 	ControllableViewBase* curView = viewController->currentView();
       
   608   if ( curView && curView->type() == "webView" ){
       
   609 
       
   610     m_urlSearchEditor->setTitle(text);
       
   611 
       
   612   }
       
   613 }
       
   614 
       
   615 QString GUrlSearchItem::getWindowsViewTitle() {
       
   616     QString title =  currentTitle();
       
   617     if (title.isEmpty()) {
       
   618         title = qtTrId("txt_browser_windows_windows");
       
   619         title += ": ";
       
   620         title += qtTrId("txt_browser_windows_new_window");
       
   621     }
       
   622     else {
       
   623         title.prepend(": ");
       
   624         title.prepend(qtTrId("txt_browser_windows_windows"));
       
   625             
       
   626     }
       
   627     return title;
       
   628 }
       
   629 #endif
   406 
   630 
   407 void GUrlSearchItem::urlSearchActivatedByEnterKey()
   631 void GUrlSearchItem::urlSearchActivatedByEnterKey()
   408 {
   632 {
   409     m_urlSearchEditor->removeFocus();
   633     m_urlSearchEditor->removeFocus();
   410     urlSearchActivated();
   634     urlSearchActivated();
   411 }
   635 }
   412 
   636 
   413 void GUrlSearchItem::urlSearchActivated()
   637 void GUrlSearchItem::urlSearchActivated()
   414 {
   638 {
   415     WebPageController * pageController = WebPageController::getSingleton();
   639     WebPageController * pageController = WebPageController::getSingleton();
   416     switch (pageController->loadState()) {
   640 	switch (pageController->loadState()) {
   417         case WRT::LoadController::GotoModeLoading:
   641 		case WRT::LoadController::GotoModeLoading:
   418             pageController->currentStop();
   642 			pageController->currentStop();
   419             ++m_pendingClearCalls;
   643 			++m_pendingClearCalls;
   420             QTimer::singleShot(500, this, SLOT(clearProgress()));
   644 			QTimer::singleShot(500, this, SLOT(clearProgress()));
   421             break;
   645 		break;
   422         case WRT::LoadController::GotoModeEditing:
   646 		case WRT::LoadController::GotoModeEditing:
   423             loadToMainWindow();
   647 			loadToMainWindow();
   424             break;
   648 		break;
   425         case WRT::LoadController::GotoModeReloadable:
   649 		case WRT::LoadController::GotoModeReloadable:
   426             if (pageController->currentDocUrl() == m_urlSearchEditor->text())
   650 			if (pageController->currentDocUrl() == m_urlSearchEditor->text())
   427                 pageController->currentReload();
   651 				pageController->currentReload();
   428             else
   652 			else
   429                 loadToMainWindow();
   653 				loadToMainWindow();
   430             break;
   654 		break;
   431         default:
   655 		default:
   432             qDebug() << "Incorrect state";
   656 			qDebug() << "GUrlSearchItem::urlSearchActivated() Incorrect state";
   433             break;
   657 		break;
   434     }
   658 	}
   435     updateUrlSearchBtn();
   659 	updateUrlSearchBtn();
   436 }
   660 }
   437 
   661 
   438 void GUrlSearchItem::updateUrlSearchBtn()
   662 void GUrlSearchItem::updateUrlSearchBtn()
   439 {
   663 {
   440     WebPageController * pageController = WebPageController::getSingleton();
   664     WebPageController * pageController = WebPageController::getSingleton();
   441     switch (pageController->loadState()) {
   665     switch (pageController->loadState()) {
   442         case WRT::LoadController::GotoModeLoading:
   666         case WRT::LoadController::GotoModeLoading:
   443             m_urlSearchBtn->addIcon(STOP_BUTTON_ICON);
   667             m_urlSearchBtn->addIcon(STOP_BUTTON_ICON);
   444             break;
   668             break;
       
   669         case WRT::LoadController::GotoModeEditinLoading:
   445         case WRT::LoadController::GotoModeEditing:
   670         case WRT::LoadController::GotoModeEditing:
   446             m_urlSearchBtn->addIcon(GO_BUTTON_ICON);
   671             m_urlSearchBtn->addIcon(GO_BUTTON_ICON);
   447             break;
   672             break;
   448         case WRT::LoadController::GotoModeReloadable:
   673         case WRT::LoadController::GotoModeReloadable:
       
   674 #ifdef BROWSER_LAYOUT_TENONE
       
   675             m_urlSearchBtn->addIcon(GO_BUTTON_ICON);
       
   676 #else
   449             m_urlSearchBtn->addIcon(REFRESH_BUTTON_ICON);
   677             m_urlSearchBtn->addIcon(REFRESH_BUTTON_ICON);
       
   678 #endif
   450             break;
   679             break;
   451         default:
   680         default:
   452             qDebug() << "Incorrect state";
   681             qDebug() << "GUrlSearchItem::updateUrlSearchBtn Incorrect state";
   453             break;
   682             break;
   454     }
   683     }
   455     m_urlSearchBtn->update();
   684     m_urlSearchBtn->update();
   456     
   685     
   457     // notify suggest object of changes in load state
   686     // notify suggest object of changes in load state
   463 }
   692 }
   464 
   693 
   465 void GUrlSearchItem::loadToMainWindow()
   694 void GUrlSearchItem::loadToMainWindow()
   466 {
   695 {
   467     QString url = m_urlSearchEditor->text();
   696     QString url = m_urlSearchEditor->text();
       
   697     if(!url.contains(KBOOKMARKURLFILESLASH)){
       
   698        if(url.contains(KBOOKMARKURLFILE))
       
   699           url.replace(QString(KBOOKMARKURLFILE), QString(KBOOKMARKURLFILESLASH));
       
   700     }
   468     WebPageController * pageController = WebPageController::getSingleton();
   701     WebPageController * pageController = WebPageController::getSingleton();
   469     QString gotourl = pageController->guessUrlFromString(url);
   702     QString gotourl = pageController->guessUrlFromString(url);
   470     m_urlSearchEditor->setText(gotourl);
   703     setUrlText(gotourl);
   471     pageController->currentLoad(gotourl);
   704     pageController->currentLoad(gotourl);
   472     pageController->urlTextChanged(gotourl);
   705     pageController->urlTextChanged(gotourl);
   473 }
   706 #ifdef BROWSER_LAYOUT_TENONE
   474 
   707     m_urlSearchEditor->closeVKB();
   475 void GUrlSearchItem::updateLoadState()
   708 #endif
   476 {
   709 }
   477     WebPageController * pageController = WebPageController::getSingleton();
   710 
   478     if (pageController->loadState() == WRT::LoadController::GotoModeReloadable) {
   711 void GUrlSearchItem::updateLoadStateAndSuggest(int /*position*/, int charsRemoved, int charsAdded)
   479         pageController->setLoadState(WRT::LoadController::GotoModeEditing);
   712 {
       
   713     WebPageController * pageController = WebPageController::getSingleton();
       
   714 
       
   715     // will get contentsChanged() signal on programmatic changes and sometimes 
       
   716     // position changes but we are only interested in user input
       
   717     if ((charsRemoved || charsAdded) && pageController->editMode()) {
       
   718         PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
       
   719         if (suggestSnippet) {
       
   720             QString cmd = "searchSuggests.updateUserInput();";
       
   721             suggestSnippet->evaluateJavaScript(cmd);
       
   722         }
       
   723     }
       
   724 }
       
   725 
       
   726 
       
   727 void GUrlSearchItem::changeLoadState(bool editing) {
       
   728 
       
   729     WebPageController * pageController = WebPageController::getSingleton();
       
   730     if (pageController->editMode() != editing)  {
       
   731         pageController->setEditMode(editing);
   480         updateUrlSearchBtn();
   732         updateUrlSearchBtn();
   481     }
   733     }
   482 }
   734 }
   483 
       
   484 void GUrlSearchItem::updateLoadStateAndSuggest()
       
   485 {
       
   486     updateLoadState();
       
   487     PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
       
   488     if (suggestSnippet) {
       
   489         QString cmd = "searchSuggests.updateUserInput();";
       
   490         suggestSnippet->evaluateJavaScript(cmd);
       
   491     }
       
   492 }
       
   493 
       
   494 void GUrlSearchItem::tapped(QPointF& pos)
   735 void GUrlSearchItem::tapped(QPointF& pos)
   495 {
   736 {
       
   737     changeLoadState(true);
   496     bool hitText = m_urlSearchEditor->tappedOnText(pos.x());
   738     bool hitText = m_urlSearchEditor->tappedOnText(pos.x());
   497     if (!m_justFocusIn && !hitText)
   739     if (!m_justFocusIn && !hitText)
   498         m_urlSearchEditor->unselect();
   740         m_urlSearchEditor->unselect();
   499 
   741 
   500     if (m_justFocusIn) {
   742     if (m_justFocusIn) {
   501         m_justFocusIn = false;
   743         m_justFocusIn = false;
       
   744 
   502         if (hitText && !m_urlSearchEditor->hasSelection())
   745         if (hitText && !m_urlSearchEditor->hasSelection())
   503             m_urlSearchEditor->selectAll();
   746             m_urlSearchEditor->selectAll();
   504     }
   747     }
   505 }
   748 }
   506 
   749 
   507 void GUrlSearchItem::focusChanged(bool focusIn)
   750 void GUrlSearchItem::focusChanged(bool focusIn)
   508 {
   751 {
   509     if (focusIn)
   752     // Suggestion snippet needs to know about this event.
       
   753     PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
       
   754     if (suggestSnippet) {
       
   755         QString cmd("searchSuggests.urlSearchFocusChanged(");
       
   756         cmd += focusIn ? "true);" : "false);";
       
   757         suggestSnippet->evaluateJavaScript(cmd);
       
   758     }
       
   759 
       
   760     if (focusIn) {
   510         m_justFocusIn = true;
   761         m_justFocusIn = true;
       
   762     }
   511     else {
   763     else {
   512         m_justFocusIn = false;
   764         m_justFocusIn = false;
   513         m_urlSearchEditor->unselect();
   765         m_urlSearchEditor->unselect();
   514         m_urlSearchEditor->shiftToLeftEnd();
   766         //m_urlSearchEditor->shiftToLeftEnd();
   515         
       
   516         // Suggestion snippet needs to know about this event.
       
   517         PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
       
   518         if (suggestSnippet) {
       
   519             QString cmd = "searchSuggests.urlSearchLostFocus();";
       
   520             suggestSnippet->evaluateJavaScript(cmd);
       
   521         }
       
   522     }
   767     }
   523 }
   768 }
   524 
   769 
   525 void GUrlSearchItem::resize()
   770 void GUrlSearchItem::resize()
   526 {
   771 {
   538 
   783 
   539 QString GUrlSearchItem::formattedUrl() const
   784 QString GUrlSearchItem::formattedUrl() const
   540 {
   785 {
   541     WebPageController * pageController = WebPageController::getSingleton();
   786     WebPageController * pageController = WebPageController::getSingleton();
   542     QString url = pageController->loadText();
   787     QString url = pageController->loadText();
       
   788     
   543     // for first load of the windows restored from last session
   789     // for first load of the windows restored from last session
   544     if (url.isEmpty()&& pageController->currentDocUrl().isEmpty()) {
   790     if (url.isEmpty()&& pageController->currentDocUrl().isEmpty()) {
   545         QWebHistoryItem item = pageController->currentPage()->history()->currentItem();
   791         QWebHistoryItem item = pageController->currentPage()->history()->currentItem();
   546         url = item.url().toString();
   792         url = item.url().toString();
   547     }
   793     }
       
   794 
   548     return url.replace(" ","+");
   795     return url.replace(" ","+");
   549 }
   796 }
       
   797 
       
   798 void GUrlSearchItem::setUrlText(const QString & str) 
       
   799 {
       
   800 	ViewController * viewController = m_chrome->viewController();
       
   801 	ControllableViewBase* curView = viewController->currentView();
       
   802   if ( curView && curView->type() == "webView" )
       
   803 	   m_urlSearchEditor->setText(WebPageController::getSingleton()->removeScheme(str));
       
   804 }
       
   805 
       
   806 QString GUrlSearchItem::urlToBeDisplayed() 
       
   807 {
       
   808 
       
   809     WebPageController * pageController = WebPageController::getSingleton();
       
   810     QString url = pageController->currentDocUrl();
       
   811     if (url.isEmpty() ) {
       
   812         url = pageController->currentRequestedUrl();
       
   813     }
       
   814     //qDebug() << "GUrlSearchItem::urlToBeDisplayed" << url;
       
   815     return url;
       
   816 }
       
   817 
       
   818 QString GUrlSearchItem::currentTitle() 
       
   819 {
       
   820 
       
   821     WebPageController * pageController = WebPageController::getSingleton();
       
   822     QString title  = pageController->currentDocTitle();
       
   823     if (title.isEmpty() ){ 
       
   824         title = pageController->currentPartialUrl();
       
   825     }
       
   826     return title;
       
   827 }
       
   828 
       
   829 // GUrlSearchSnippet class
       
   830 
   550 
   831 
   551 GUrlSearchSnippet::GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome,
   832 GUrlSearchSnippet::GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome,
   552                          QGraphicsWidget * widget, const QWebElement & element)
   833                          QGraphicsWidget * widget, const QWebElement & element)
   553   : ChromeSnippet(elementId, chrome, widget, element)
   834   : ChromeSnippet(elementId, chrome, widget, element)
   554 {
   835 {