[NextBrowser] Adding Hybrid Navigation for Most Visited popup 60/318860/7
authormayur.jain <mayur.jain@samsung.com>
Tue, 28 Jan 2025 09:02:13 +0000 (14:32 +0530)
committerInsoon Kim <is46.kim@samsung.com>
Mon, 24 Mar 2025 23:24:01 +0000 (23:24 +0000)
-If any other popup is also open alongside MV popup then
 normal pointer navigation will work

Change-Id: I54c43287cfa7ee2d17ab2c027d0f6deb82feaf93
Signed-off-by: mayur.jain <mayur.jain@samsung.com>
chrome/browser/ui/samsung/hybrid_navigation_controller.cc
chrome/browser/ui/samsung/hybrid_navigation_controller.h

index f98fd7bbcd103eb9c742ab2bbcc1f68191e4c652..7f0d4076d5a7bbdd1630ea585fab4df087df64dc 100644 (file)
@@ -15,6 +15,7 @@
 #include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
 #include "chrome/browser/ui/views/frame/tab_strip_region_view.h"
 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
+#include "chrome/browser/ui/views/omnibox/omnibox_popup_view_views.h"
 #include "chrome/browser/ui/views/tabs/tab_container_impl.h"
 #include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h"
 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
@@ -35,6 +36,8 @@ constexpr int tabStripMidY = 17;
 constexpr int tabStripEndY = 35;
 constexpr int toolbarMidY = 53;
 constexpr int webViewStartY = 73;
+constexpr int mvPopupStartX = 151;
+constexpr int mvPopupStartY = 72;
 
 constexpr int closeButtonX = 1898;
 
@@ -298,6 +301,13 @@ bool HybridNavigationController::KeyEvent(
 
   samsung_browser_main::NativePopupType nativePopupType = GetNativePopupType();
   LOG(INFO) << "IsAnyNativePopupOpen: " << (int)nativePopupType;
+
+  if (isDirection && !is_popup_exists_ &&
+      keyType == samsung_browser_main::KeyEventType::Pressed &&
+      HandleMVPopupNavigation(key, x, y)) {
+    LOG(INFO) << "MVNavigation done";
+    return true;
+  }
   BrowserAppMenuButton* menu_tree = browser_view_->toolbar()->app_menu_button();
   ExtensionsToolbarContainer* extensions_container =
       browser_view_->toolbar()->extensions_container();
@@ -905,6 +915,238 @@ void HybridNavigationController::OnDidChangeFocus(views::View* focused_before,
   }
 }
 
+bool HybridNavigationController::HandleMVPopupNavigation(std::string key,
+                                                         int x,
+                                                         int y) {
+  LOG(INFO) << "";
+  auto cursor_controller =
+      samsung_browser_main::SamsungBrowserCore::instance()->CursorController();
+  OmniboxPopupView* popup =
+      browser_view_->GetLocationBarView()->GetOmniboxPopupView();
+  if (popup && popup->isMVOpen()) {
+    LOG(INFO) << "MV popup is open";
+    OmniboxPopupViewViews* opvv = static_cast<OmniboxPopupViewViews*>(popup);
+
+    views::View::Views popup_container = opvv->children();
+    views::View* first_child = popup_container[0];
+    views::View::Views rows = first_child->children();
+    LOG(INFO) << "OmniboxPopupViewViews rows size: " << rows.size();
+    if (!keynameArrowDown.compare(key)) {
+      LOG(INFO) << "On KeyEvent, KEY: UP";
+      views::View* nextFocusChild = nullptr;
+      int i = 1, x_min = 1000000, y_min = 1000000, x_final = 0, y_final = 0;
+      for (views::View* row : rows) {
+        views::View::Views row_childs = row->children();
+        int j = 1;
+        for (views::View* col : row_childs) {
+          j++;
+          int child_xcord = mvPopupStartX + col->x() + (col->width()) / 2;
+          int child_ycord =
+              mvPopupStartY + row->y() + col->y() + (col->height()) / 2;
+          if (x == child_xcord && y == child_ycord) {
+            continue;
+          }
+          int x_diff = x - child_xcord;
+          int y_diff = child_ycord - y;
+          if (y_diff <= 0) {
+            continue;
+          }
+          if (x_diff < 0) {
+            x_diff = -1 * x_diff;
+          }
+          if (x_diff <= x_min && y_diff <= y_min) {
+            LOG(INFO) << "Found better element";
+            x_min = x_diff;
+            y_min = y_diff;
+            x_final = child_xcord;
+            y_final = child_ycord;
+            nextFocusChild = col;
+          }
+        }
+        i++;
+      }
+      if (nextFocusChild) {
+        LOG(INFO) << "Moving focus to -> X: " << nextFocusChild->x()
+                  << " Y: " << nextFocusChild->y()
+                  << " Width: " << nextFocusChild->width()
+                  << " height: " << nextFocusChild->height();
+        cursor_controller->MovePointerTo(x_final, y_final, true);
+        return true;
+      } else {
+        LOG(INFO) << "No element found, exiting from MV";
+        cursor_controller->MovePointerTo(
+            x, y + 70, true);  // 70 is offset to exit from last entry
+        return true;
+      }
+      return false;
+    }
+
+    else if (!keynameArrowUp.compare(key)) {
+      LOG(INFO) << "On KeyEvent, KEY: UP";
+      if (y == toolbarMidY) {
+        LOG(INFO) << "Not inside MV popup, return to outside nav.";
+        return false;
+      }
+      views::View* nextFocusChild = nullptr;
+      int i = 1, x_min = 1000000, y_min = 1000000, x_final = 0, y_final = 0;
+      for (views::View* row : rows) {
+        LOG(INFO) << "Row: " << i;
+        views::View::Views row_childs = row->children();
+        int j = 1;
+        for (views::View* col : row_childs) {
+          j++;
+          int child_xcord = mvPopupStartX + col->x() + (col->width()) / 2;
+          int child_ycord =
+              mvPopupStartY + row->y() + col->y() + (col->height()) / 2;
+          if (x == child_xcord && y == child_ycord) {
+            continue;
+          }
+          int x_diff = x - child_xcord;
+          int y_diff = y - child_ycord;
+          if (y_diff <= 0) {
+            continue;
+          }
+          if (x_diff < 0) {
+            x_diff = -1 * x_diff;
+          }
+          if (x_diff <= x_min && y_diff <= y_min) {
+            LOG(INFO) << "Found better element";
+            x_min = x_diff;
+            y_min = y_diff;
+            x_final = child_xcord;
+            y_final = child_ycord;
+            nextFocusChild = col;
+          }
+        }
+        i++;
+      }
+      if (nextFocusChild) {
+        LOG(INFO) << "Moving focus to -> X: " << nextFocusChild->x()
+                  << " Y: " << nextFocusChild->y()
+                  << " Width: " << nextFocusChild->width()
+                  << " height: " << nextFocusChild->height();
+        cursor_controller->MovePointerTo(x_final, y_final, true);
+        return true;
+      } else {
+        LOG(INFO) << "No element found, exiting from MV";
+        cursor_controller->MovePointerTo(923, 53,
+                                         true);  // moving to center of url bar
+        return true;
+      }
+      return false;
+    }
+
+    else if (!keynameArrowLeft.compare(key)) {
+      LOG(INFO) << "On KeyEvent, KEY: UP";
+      if (y <= toolbarMidY) {
+        LOG(INFO) << "Not inside MV popup, return to outside nav.";
+        return false;
+      }
+      views::View* nextFocusChild = nullptr;
+      int i = 1, x_min = 1000000, y_min = 1000000, x_final = 0, y_final = 0;
+      for (views::View* row : rows) {
+        views::View::Views row_childs = row->children();
+        int j = 1;
+        for (views::View* col : row_childs) {
+          j++;
+          int child_xcord = mvPopupStartX + col->x() + (col->width()) / 2;
+          int child_ycord =
+              mvPopupStartY + row->y() + col->y() + (col->height()) / 2;
+          if (x == child_xcord && y == child_ycord) {
+            continue;
+          }
+          int x_diff = x - child_xcord;
+          int y_diff = y - child_ycord;
+          if (x_diff <= 0) {
+            continue;
+          }
+          if (y_diff < 0) {
+            y_diff = -1 * y_diff;
+          }
+          if (x_diff <= x_min && y_diff <= y_min) {
+            LOG(INFO) << "Found better element";
+            x_min = x_diff;
+            y_min = y_diff;
+            x_final = child_xcord;
+            y_final = child_ycord;
+            nextFocusChild = col;
+          }
+        }
+        i++;
+      }
+      if (nextFocusChild) {
+        LOG(INFO) << "Moving focus to -> X: " << nextFocusChild->x()
+                  << " Y: " << nextFocusChild->y()
+                  << " Width: " << nextFocusChild->width()
+                  << " height: " << nextFocusChild->height();
+        cursor_controller->MovePointerTo(x_final, y_final, true);
+        return true;
+      } else {
+        LOG(INFO) << "No element found, exiting from MV";
+        cursor_controller->MovePointerTo(
+            x - 260, y, true);  // 260 is offset to exit from left side of MV
+        return true;
+      }
+      return false;
+    }
+
+    else if (!keynameArrowRight.compare(key)) {
+      LOG(INFO) << "On KeyEvent, KEY: UP";
+      if (y <= toolbarMidY) {
+        LOG(INFO) << "Not inside MV popup, return to outside nav.";
+        return false;
+      }
+      views::View* nextFocusChild = nullptr;
+      int i = 1, x_min = 1000000, y_min = 1000000, x_final = 0, y_final = 0;
+      for (views::View* row : rows) {
+        views::View::Views row_childs = row->children();
+        int j = 1;
+        for (views::View* col : row_childs) {
+          j++;
+          int child_xcord = mvPopupStartX + col->x() + (col->width()) / 2;
+          int child_ycord =
+              mvPopupStartY + row->y() + col->y() + (col->height()) / 2;
+          if (x == child_xcord && y == child_ycord) {
+            continue;
+          }
+          int x_diff = child_xcord - x;
+          int y_diff = y - child_ycord;
+          if (x_diff <= 0) {
+            continue;
+          }
+          if (y_diff != 0) {
+            continue;
+          }
+          if (x_diff <= x_min && y_diff <= y_min) {
+            LOG(INFO) << "Found better element";
+            x_min = x_diff;
+            y_min = y_diff;
+            x_final = child_xcord;
+            y_final = child_ycord;
+            nextFocusChild = col;
+          }
+        }
+        i++;
+      }
+      if (nextFocusChild) {
+        LOG(INFO) << "Moving focus to -> X: " << nextFocusChild->x()
+                  << " Y: " << nextFocusChild->y()
+                  << " Width: " << nextFocusChild->width()
+                  << " height: " << nextFocusChild->height();
+        cursor_controller->MovePointerTo(x_final, y_final, true);
+        return true;
+      } else {
+        LOG(INFO) << "No element found, exiting from MV";
+        cursor_controller->MovePointerTo(
+            1730, y, true);  // 1730 is offset to exit from right side of MV
+        return true;
+      }
+      return false;
+    }
+  }
+  return false;
+}
+
 void HybridNavigationController::handleWebViewArea(std::string key,
                                                    int x,
                                                    int y) {
index c4ba7580ac8a77e5459c031f31197293a8152b33..b4b793c70ddbc94384a95b6d8ca50f72f807a27f 100644 (file)
@@ -40,6 +40,7 @@ class HybridNavigationController
   bool Init();
   void DeInit();
   bool ReInit(Browser* browser);
+  bool HandleMVPopupNavigation(std::string key, int x, int y);
   void handleWebViewArea(std::string key, int x, int y);
   void handleToolbarViewArea(std::string key, int x, int y);
   void handleTabstripViewArea(std::string key, int x, int y);