[NextBrowser][WIP] Pin tab implementation 14/324214/2
authoracedrapiza <a.drapiza@samsung.com>
Wed, 14 May 2025 03:07:34 +0000 (11:07 +0800)
committerBot Blink <blinkbot@samsung.com>
Thu, 15 May 2025 12:49:04 +0000 (12:49 +0000)
- Added pin tab button on toolbar
- Limit pinned tabs to 2
- Update icon and tooltip when TabPinnedStateChanged

Change-Id: I10e87c8ce8d4aba32dffd33b0a6932141d566a8d
Signed-off-by: acedrapiza <a.drapiza@samsung.com>
chrome/browser/ui/browser.cc
chrome/browser/ui/tabs/tab_strip_model.cc
chrome/browser/ui/views/toolbar/toolbar_view.cc
chrome/browser/ui/views/toolbar/toolbar_view.h

index bbaa39e67c8b3e2dc341db11ed3c3990b2670eea..7693ea5cc967fe92914e5a9f29348fea73af1d86 100644 (file)
@@ -1318,6 +1318,13 @@ void Browser::TabPinnedStateChanged(TabStripModel* tab_strip_model,
     session_service->SetPinnedState(session_id(),
                                     session_tab_helper->session_id(),
                                     tab_strip_model_->IsTabPinned(index));
+#if defined(SAMSUNG_TOOLBAR_UI)
+    BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(this);
+    if (browser_view && browser_view->toolbar()) {
+      ToolbarView* toolbar_view_ = browser_view->toolbar();
+      toolbar_view_->UpdatePinTabButtonState();
+    }
+#endif
   }
 }
 
index 66239185aa0153651edaf5cee8c4bfd5236e8163..cb1e5d731d0f2fba991a4d431a110441a1bc195a 100644 (file)
@@ -1471,6 +1471,11 @@ void TabStripModel::ExecuteContextMenuCommand(int context_index,
       base::RecordAction(UserMetricsAction("TabContextMenu_TogglePinned"));
       std::vector<int> indices = GetIndicesForCommand(context_index);
       bool pin = WillContextMenuPin(context_index);
+#if defined(SAMSUNG_NEXT_BROWSER)
+      int total_pinned_count = IndexOfFirstNonPinnedTab();
+      if (pin && total_pinned_count >= 2)
+        break;
+#endif
       SetTabsPinned(indices, pin);
       break;
     }
index 3b9dec1da4bca786e8233cdea75f1d943b4f953d..2958cd95a5c6f0eefc8d7079a48f2fd7b7e64e3d 100644 (file)
 
 #if defined(SAMSUNG_TOOLBAR_UI)
 #include "chrome/browser/ui/views/samsung/bookmarks/bookmarks_bubble_view.h"
+#include "chrome/browser/ui/views/samsung/exit_browser_bubble_view.h"
 #include "chrome/browser/ui/views/samsung/handoff/handoff_bubble_view.h"
 #include "chrome/browser/ui/views/samsung/handoff/handoff_timeout_bubble_view.h"
-#include "chrome/browser/ui/views/samsung/exit_browser_bubble_view.h"
 #include "chrome/browser/ui/views/samsung/passkey/passkey_bubble_view.h"
+#include "ui/views/vector_icons.h"
 #endif //SAMSUNG_TOOLBAR_UI
 
 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
@@ -468,6 +469,24 @@ void ToolbarView::Init() {
   auto image_model = ui::ImageModel::FromVectorIcon(
       kZoomMinusMenuRefreshIcon, ui::kColorMenuItemForeground);
 
+  WebContents* current_tab = GetWebContents();
+  const int index =
+      browser_->tab_strip_model()->GetIndexOfWebContents(current_tab);
+
+  bool is_current_tab_pinned = false;
+  if (index != TabStripModel::kNoTab)
+    is_current_tab_pinned = browser_->tab_strip_model()->IsTabPinned(index);
+
+  std::unique_ptr<views::Button> pin_button = CreateButtonWithAccessibleName(
+      base::BindRepeating(callback, browser_, IDC_WINDOW_PIN_TAB),
+      IDS_ACCNAME_ZOOM_MINUS2, false, true,
+      ui::ImageModel::FromVectorIcon(
+          is_current_tab_pinned ? views::kUnpinIcon : views::kPinIcon,
+          ui::kColorMenuItemForeground));
+
+  std::unique_ptr<views::ImageButton> pintab_button(
+      static_cast<views::ImageButton*>(pin_button.release()));
+
   std::unique_ptr<views::Button> decrement_button =
       CreateButtonWithAccessibleName(
           base::BindRepeating(callback, browser_, IDC_ZOOM_MINUS),
@@ -649,6 +668,7 @@ void ToolbarView::Init() {
   if (media_button)
     media_button_ = container_view_->AddChildView(std::move(media_button));
 #if defined(SAMSUNG_TOOLBAR_UI)
+  pintab_button_ = container_view_->AddChildView(std::move(pintab_button));
   decrement_button_ =
       container_view_->AddChildView(std::move(decrement_button));
   zoom_label_ = container_view_->AddChildView(std::move(zoom_label));
@@ -752,6 +772,53 @@ void ToolbarView::UpdateZoomMenuTheme() {
   inc_button->UpdateIconsWithStandardColors(kZoomPlusMenuRefreshIcon);
 }
 
+void ToolbarView::UpdatePinTabButtonState() {
+  bool isWebApp = browser_view_->GetIsWebAppType();
+  if (isWebApp) {
+    LOG(INFO) << "No pin in PWA, returning";
+    return;
+  }
+
+  WebContents* current_tab = GetWebContents();
+  const int current_tab_index =
+      browser_->tab_strip_model()->GetIndexOfWebContents(current_tab);
+  bool is_current_tab_pinned =
+      browser_->tab_strip_model()->IsTabPinned(current_tab_index);
+
+  pintab_button_->SetImageModel(
+      views::Button::STATE_NORMAL,
+      ui::ImageModel::FromVectorIcon(
+          is_current_tab_pinned ? views::kUnpinIcon : views::kPinIcon,
+          ui::kColorMenuItemForeground));
+
+  auto browser_core = samsung_browser_main::SamsungBrowserCore::instance();
+  if (!browser_core) {
+    LOG(INFO) << "browser_core is null";
+    return;
+  }
+
+  auto multi_language_controller = browser_core->MultiLanguageController();
+  if (!multi_language_controller) {
+    LOG(INFO) << "multi_language_controller is null";
+    return;
+  }
+
+  int pinned_count = browser_->tab_strip_model()->IndexOfFirstNonPinnedTab();
+  if (pinned_count >= 2 && !is_current_tab_pinned) {
+    pintab_button_->SetTooltipText(multi_language_controller->GetUTF16String(
+        "TV_SID_WEBBROWSER_CEAUG_TO_PIN_TAB_UNPIN_THE_PREVIOUS_ONE"));
+    return;
+  }
+
+  if (is_current_tab_pinned) {
+    pintab_button_->SetTooltipText(multi_language_controller->GetUTF16String(
+        "TV_SID_WEBBROWSER_CEAUG_UNPIN_TAB"));
+  } else {
+    pintab_button_->SetTooltipText(multi_language_controller->GetUTF16String(
+        "TV_SID_WEBBROWSER_CEAUG_PIN_TAB"));
+  }
+}
+
 void ToolbarView::UpdateButtonToolTips() {
   auto browser_core = samsung_browser_main::SamsungBrowserCore::instance();
   if (!browser_core) {
@@ -795,6 +862,7 @@ void ToolbarView::Update(WebContents* tab) {
   if (tab) {
     LOG(INFO) << "Updating Zoom value";
     UpdateZoomControls();
+    UpdatePinTabButtonState();
   }
 #endif
   if (location_bar_)
index 7d5c8d180989bc4303cb4367f18017330147643d..d4a36f38f634aaff13624af616cb645bf7b6be58 100644 (file)
@@ -236,6 +236,7 @@ class ToolbarView : public views::AccessiblePaneView,
   void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
   void UpdateZoomControls();
   void UpdateZoomMenuTheme();
+  void UpdatePinTabButtonState();
 #endif
 
  private:
@@ -308,6 +309,7 @@ class ToolbarView : public views::AccessiblePaneView,
   // view hierarchy.
 #if defined(SAMSUNG_TOOLBAR_UI)
   base::CallbackListSubscription browser_zoom_subscription_;
+  raw_ptr<views::ImageButton> pintab_button_ = nullptr;
   raw_ptr<views::Button> decrement_button_ = nullptr;
   raw_ptr<views::Label> zoom_label_ = nullptr;
   raw_ptr<views::Button> increment_button_ = nullptr;