ginebra2/UrlSearchSnippet.cpp
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    21 
    21 
    22 #include "UrlSearchSnippet.h"
    22 #include "UrlSearchSnippet.h"
    23 #include "Utilities.h"
    23 #include "Utilities.h"
    24 
    24 
    25 #include "ChromeRenderer.h"
    25 #include "ChromeRenderer.h"
       
    26 #include "ChromeLayout.h"
    26 #include "ChromeWidget.h"
    27 #include "ChromeWidget.h"
    27 #include "PageSnippet.h"
    28 #include "PageSnippet.h"
    28 #include "ViewController.h"
    29 #include "ViewController.h"
    29 #include "ViewStack.h"
    30 #include "ViewStack.h"
    30 #include "WebChromeSnippet.h"
    31 #include "WebChromeSnippet.h"
    31 #include "LoadController.h"
    32 #include "LoadController.h"
    32 #include "webpagecontroller.h"
    33 #include "webpagecontroller.h"
    33 #include "GWebContentView.h"
    34 #include "GWebContentView.h"
    34 #include "WindowFlowView.h"
    35 #include "WindowFlowView.h"
    35 
    36 
       
    37 #include <QWebHistoryItem>
       
    38 
    36 namespace GVA {
    39 namespace GVA {
    37 
    40 
    38 #define GO_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/go_btn.png"
    41 #define GO_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/go_btn.png"
    39 #define STOP_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/stop_btn.png"
    42 #define STOP_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/stop_btn.png"
    40 #define REFRESH_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/refresh_btn.png"
    43 #define REFRESH_BUTTON_ICON ":/chrome/bedrockchrome/urlsearch.snippet/icons/refresh_btn.png"
    93     m_urlSearchEditor->setTextColor(textColor);
    96     m_urlSearchEditor->setTextColor(textColor);
    94     m_urlSearchEditor->setBackgroundColor(backgroundColor);
    97     m_urlSearchEditor->setBackgroundColor(backgroundColor);
    95     m_urlSearchEditor->setProgressColor(progressColor);
    98     m_urlSearchEditor->setProgressColor(progressColor);
    96     m_urlSearchEditor->setBorderColor(m_borderColor);
    99     m_urlSearchEditor->setBorderColor(m_borderColor);
    97     m_urlSearchEditor->setPadding(0.1); // draw the Rounded Rect
   100     m_urlSearchEditor->setPadding(0.1); // draw the Rounded Rect
       
   101     m_urlSearchEditor->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
    98     safe_connect(m_urlSearchEditor, SIGNAL(textMayChanged()), this, SLOT(updateLoadStateAndSuggest()));
   102     safe_connect(m_urlSearchEditor, SIGNAL(textMayChanged()), this, SLOT(updateLoadStateAndSuggest()));
    99     safe_connect(m_urlSearchEditor, SIGNAL(activated()),this, SLOT(urlSearchActivatedByEnterKey()));
   103     safe_connect(m_urlSearchEditor, SIGNAL(activated()),this, SLOT(urlSearchActivatedByEnterKey()));
   100     safe_connect(m_urlSearchEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool)));
   104     safe_connect(m_urlSearchEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool)));
   101     safe_connect(m_urlSearchEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&)));
   105     safe_connect(m_urlSearchEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&)));
   102 
   106 
   103     // Create the url search button
   107     // Create the url search button
   104     m_urlSearchBtn = new ActionButton(snippet, m_viewPort);
   108     m_urlSearchBtn = new ActionButton(snippet, m_viewPort);
   105     QAction* urlSearchBtnAction = new QAction(this);
   109     QAction* urlSearchBtnAction = new QAction(this);
   106     m_urlSearchBtn->setAction(urlSearchBtnAction); // FIXME: should use diff QActions
   110     m_urlSearchBtn->setAction(urlSearchBtnAction); // FIXME: should use diff QActions
       
   111 
       
   112     m_urlSearchBtn->setActiveOnPress(false);
   107     safe_connect(urlSearchBtnAction, SIGNAL(triggered()), this, SLOT(urlSearchActivated()));
   113     safe_connect(urlSearchBtnAction, SIGNAL(triggered()), this, SLOT(urlSearchActivated()));
   108 
   114 
   109     // Get the icon size
   115     // Get the icon size
   110     QIcon btnIcon(GO_BUTTON_ICON);
   116     QIcon btnIcon(GO_BUTTON_ICON);
   111     QSize defaultSize(50, 50);
   117     QSize defaultSize(50, 50);
   148     ViewController * viewController = chrome->viewController();
   154     ViewController * viewController = chrome->viewController();
   149 
   155 
   150     safe_connect(viewController, SIGNAL(currentViewChanged()),
   156     safe_connect(viewController, SIGNAL(currentViewChanged()),
   151             this, SLOT(viewChanged()));
   157             this, SLOT(viewChanged()));
   152 
   158 
   153     safe_connect(ViewStack::getSingleton(), SIGNAL(currentViewChanged()),
   159  /*   safe_connect(ViewStack::getSingleton(), SIGNAL(currentViewChanged()),
   154             this, SLOT(viewChanged()));
   160             this, SLOT(viewChanged()));*/
   155 }
   161 }
   156 
   162 
   157 GUrlSearchItem::~GUrlSearchItem()
   163 GUrlSearchItem::~GUrlSearchItem()
   158 {
   164 {
   159 }
   165 }
   249     ControllableViewBase* curView = viewController->currentView();
   255     ControllableViewBase* curView = viewController->currentView();
   250     if (curView && curView->type() == "webView") {
   256     if (curView && curView->type() == "webView") {
   251         GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   257         GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   252         bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   258         bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   253         if(!isSuperPage)
   259         if(!isSuperPage)
   254             m_chrome->slideView(100);
   260 	  m_chrome->layout()->slideView(100);
   255     }
   261     }
   256     // Strictly speaking we should set progress to 0.
   262     // Strictly speaking we should set progress to 0.
   257     // But set it higher to give immediate visual feedback
   263     // But set it higher to give immediate visual feedback
   258     // that something is happening.
   264     // that something is happening.
   259 
   265 
   310     m_urlSearchEditor->removeFocus();
   316     m_urlSearchEditor->removeFocus();
   311 
   317 
   312     ViewController * viewController = m_chrome->viewController();
   318     ViewController * viewController = m_chrome->viewController();
   313     ControllableViewBase* curView = viewController->currentView();
   319     ControllableViewBase* curView = viewController->currentView();
   314     if (curView && curView->type() == "webView" && pageController->contentsYPos() > 0)
   320     if (curView && curView->type() == "webView" && pageController->contentsYPos() > 0)
   315         m_chrome->slideView(-100);
   321       m_chrome->layout()->slideView(-100);
   316 
   322 
   317     ++m_pendingClearCalls;
   323     ++m_pendingClearCalls;
   318 
   324 
   319     QTimer::singleShot(500, this, SLOT(clearProgress()));
   325     QTimer::singleShot(500, this, SLOT(clearProgress()));
   320 }
   326 }
   321 
   327 
   322 void GUrlSearchItem::setPageCreated()
   328 void GUrlSearchItem::setPageCreated()
   323 {
   329 {
   324     // remove slideview(100) since the new transition for the code-driven window
   330     // remove slideview(100) since the new transition for the code-driven window
   325     //m_chrome->slideView(100);
   331     //m_chrome->layout()->slideView(100);
   326 }
   332 }
   327 
   333 
   328 void GUrlSearchItem::setPageChanged()
   334 void GUrlSearchItem::setPageChanged()
   329 {
   335 {
   330     m_urlSearchEditor->setText(formattedUrl());
   336     m_urlSearchEditor->setText(formattedUrl());
   361     GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   367     GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
   362     bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   368     bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
   363 
   369 
   364     // view changes to web content view
   370     // view changes to web content view
   365     if (curView && curView->type() == "webView" && !isSuperPage) {
   371     if (curView && curView->type() == "webView" && !isSuperPage) {
   366         m_urlSearchEditor->setText(formattedUrl());
       
   367         int progress = pageController->loadProgressValue();
   372         int progress = pageController->loadProgressValue();
   368         if (progress >= 100)
   373         if (progress >= 100)
   369             progress = 0;
   374             progress = 0;
   370         m_urlSearchEditor->setProgress(progress);
   375         m_urlSearchEditor->setProgress(progress);
   371         updateUrlSearchBtn();
   376         updateUrlSearchBtn();
   380             else {
   385             else {
   381                 m_urlSearchEditor->grabFocus();
   386                 m_urlSearchEditor->grabFocus();
   382             }
   387             }
   383         }
   388         }
   384         if (!isSuperPage  && (pageController->contentsYPos() <= 0 || pageController->isPageLoading())){
   389         if (!isSuperPage  && (pageController->contentsYPos() <= 0 || pageController->isPageLoading())){
   385             m_chrome->slideView(100);
   390 	  m_chrome->layout()->slideView(100);
   386         } else {
   391         } else {
   387             m_chrome->slideView(-100);
   392 	  m_chrome->layout()->slideView(-100);
   388         }
   393         }
   389         m_backFromNewWinTrans = false;
   394         m_backFromNewWinTrans = false;
   390     } else {
   395     } else {
   391          pageController->urlTextChanged(m_urlSearchEditor->text());
   396          pageController->urlTextChanged(m_urlSearchEditor->text());
   392          // Remove progress bar and url text field value so that
   397          // Remove progress bar
   393          // incorrect values are not seen before we can update when we come back
   398          // incorrect values are not seen before we can update when we come back
   394          m_urlSearchEditor->setText("");
       
   395          m_urlSearchEditor->setProgress(0);
   399          m_urlSearchEditor->setProgress(0);
   396          m_chrome->slideView(-100);
   400          m_chrome->layout()->slideView(-100);
   397     }
   401     }
   398 }
   402 }
   399 
   403 
   400 void GUrlSearchItem::urlSearchActivatedByEnterKey()
   404 void GUrlSearchItem::urlSearchActivatedByEnterKey()
   401 {
   405 {
   503         m_justFocusIn = true;
   507         m_justFocusIn = true;
   504     else {
   508     else {
   505         m_justFocusIn = false;
   509         m_justFocusIn = false;
   506         m_urlSearchEditor->unselect();
   510         m_urlSearchEditor->unselect();
   507         m_urlSearchEditor->shiftToLeftEnd();
   511         m_urlSearchEditor->shiftToLeftEnd();
       
   512         
       
   513         // Suggestion snippet needs to know about this event.
       
   514         PageSnippet * suggestSnippet = qobject_cast<PageSnippet*>(m_chrome->getSnippet("SuggestsChromeId"));
       
   515         if (suggestSnippet) {
       
   516             QString cmd = "searchSuggests.urlSearchLostFocus();";
       
   517             suggestSnippet->evaluateJavaScript(cmd);
       
   518         }
   508     }
   519     }
   509 }
   520 }
   510 
   521 
   511 void GUrlSearchItem::resize()
   522 void GUrlSearchItem::resize()
   512 {
   523 {
   523 }
   534 }
   524 
   535 
   525 QString GUrlSearchItem::formattedUrl() const
   536 QString GUrlSearchItem::formattedUrl() const
   526 {
   537 {
   527     WebPageController * pageController = WebPageController::getSingleton();
   538     WebPageController * pageController = WebPageController::getSingleton();
   528     return pageController->currentDocUrl().replace(" ","+");
   539     QString url = pageController->loadText();
       
   540     // for first load of the windows restored from last session
       
   541     if (url.isEmpty()&& pageController->currentDocUrl().isEmpty()) {
       
   542         QWebHistoryItem item = pageController->currentPage()->history()->currentItem();
       
   543         url = item.url().toString();
       
   544     }
       
   545     return url.replace(" ","+");
   529 }
   546 }
   530 
   547 
   531 GUrlSearchSnippet::GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome,
   548 GUrlSearchSnippet::GUrlSearchSnippet(const QString & elementId, ChromeWidget * chrome,
   532                          QGraphicsWidget * widget, const QWebElement & element)
   549                          QGraphicsWidget * widget, const QWebElement & element)
   533   : ChromeSnippet(elementId, chrome, widget, element)
   550   : ChromeSnippet(elementId, chrome, widget, element)
   534 {
   551 {
   535 }
   552 }
   536 
   553 
       
   554 GUrlSearchSnippet * GUrlSearchSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
       
   555 {
       
   556     GUrlSearchSnippet* that = new GUrlSearchSnippet(elementId, chrome, 0, element);
       
   557     that->setChromeWidget( new GUrlSearchItem( that, chrome ) );
       
   558     return that;
       
   559 }
       
   560 
   537 inline GUrlSearchItem* GUrlSearchSnippet::urlSearchItem()
   561 inline GUrlSearchItem* GUrlSearchSnippet::urlSearchItem()
   538 {
   562 {
   539     return static_cast<GUrlSearchItem *>(widget());
   563     return static_cast<GUrlSearchItem *>(widget());
   540 }
   564 }
   541 
   565