Przeglądaj źródła

Browser+Ladybird+LibWebView: Consolidate title handling in LibWebView

Namely, let's have empty titles behave the same in both Browser and
Ladybird (display the URL).
Timothy Flynn 2 lat temu
rodzic
commit
5a3825b561

+ 3 - 9
Ladybird/BrowserWindow.cpp

@@ -516,15 +516,9 @@ int BrowserWindow::tab_index(Tab* tab)
 
 
 void BrowserWindow::tab_title_changed(int index, QString const& title)
 void BrowserWindow::tab_title_changed(int index, QString const& title)
 {
 {
-    if (title.isEmpty()) {
-        m_tabs_container->setTabText(index, "...");
-        if (m_tabs_container->currentIndex() == index)
-            setWindowTitle("Ladybird");
-    } else {
-        m_tabs_container->setTabText(index, title);
-        if (m_tabs_container->currentIndex() == index)
-            setWindowTitle(QString("%1 - Ladybird").arg(title));
-    }
+    m_tabs_container->setTabText(index, title);
+    if (m_tabs_container->currentIndex() == index)
+        setWindowTitle(QString("%1 - Ladybird").arg(title));
 }
 }
 
 
 void BrowserWindow::tab_favicon_changed(int index, QIcon icon)
 void BrowserWindow::tab_favicon_changed(int index, QIcon icon)

+ 4 - 8
Userland/Applications/Browser/Tab.cpp

@@ -428,14 +428,10 @@ Tab::Tab(BrowserWindow& window)
         view().on_link_click(href, "_blank", 0);
         view().on_link_click(href, "_blank", 0);
     };
     };
 
 
-    view().on_title_change = [this](auto& title) {
-        if (title.is_null()) {
-            m_history.update_title(url().to_deprecated_string());
-            m_title = url().to_deprecated_string();
-        } else {
-            m_history.update_title(title);
-            m_title = title;
-        }
+    view().on_title_change = [this](auto const& title) {
+        m_history.update_title(title);
+        m_title = title;
+
         if (on_title_change)
         if (on_title_change)
             on_title_change(m_title);
             on_title_change(m_title);
     };
     };

+ 6 - 1
Userland/Libraries/LibWebView/WebContentClient.cpp

@@ -95,7 +95,12 @@ void WebContentClient::did_change_title(DeprecatedString const& title)
 {
 {
     dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeTitle! title={}", title);
     dbgln_if(SPAM_DEBUG, "handle: WebContentClient::DidChangeTitle! title={}", title);
 
 
-    if (m_view.on_title_change)
+    if (!m_view.on_title_change)
+        return;
+
+    if (title.is_empty())
+        m_view.on_title_change(m_view.url().to_deprecated_string());
+    else
         m_view.on_title_change(title);
         m_view.on_title_change(title);
 }
 }