| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/views/chrome_menu.h" | 5 #include "chrome/views/chrome_menu.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
| 9 #include <Vssym32.h> | 9 #include <Vssym32.h> |
| 10 | 10 |
| (...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 return; | 1728 return; |
| 1729 | 1729 |
| 1730 if (possible_drag_) { | 1730 if (possible_drag_) { |
| 1731 if (ChromeViews::View::ExceededDragThreshold(event.x() - press_x_, | 1731 if (ChromeViews::View::ExceededDragThreshold(event.x() - press_x_, |
| 1732 event.y() - press_y_)) { | 1732 event.y() - press_y_)) { |
| 1733 MenuItemView* item = state_.item; | 1733 MenuItemView* item = state_.item; |
| 1734 DCHECK(item); | 1734 DCHECK(item); |
| 1735 // Points are in the coordinates of the submenu, need to map to that of | 1735 // Points are in the coordinates of the submenu, need to map to that of |
| 1736 // the selected item. Additionally source may not be the parent of | 1736 // the selected item. Additionally source may not be the parent of |
| 1737 // the selected item, so need to map to screen first then to item. | 1737 // the selected item, so need to map to screen first then to item. |
| 1738 CPoint press_loc(press_x_, press_y_); | 1738 gfx::Point press_loc(press_x_, press_y_); |
| 1739 View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); | 1739 View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); |
| 1740 View::ConvertPointToView(NULL, item, &press_loc); | 1740 View::ConvertPointToView(NULL, item, &press_loc); |
| 1741 CPoint drag_loc(event.x(), event.y()); | 1741 gfx::Point drag_loc(event.location()); |
| 1742 View::ConvertPointToScreen(source->GetScrollViewContainer(), &drag_loc); | 1742 View::ConvertPointToScreen(source->GetScrollViewContainer(), &drag_loc); |
| 1743 View::ConvertPointToView(NULL, item, &drag_loc); | 1743 View::ConvertPointToView(NULL, item, &drag_loc); |
| 1744 in_drag_ = true; | 1744 in_drag_ = true; |
| 1745 ChromeCanvas canvas(item->width(), item->height(), false); | 1745 ChromeCanvas canvas(item->width(), item->height(), false); |
| 1746 item->Paint(&canvas, true); | 1746 item->Paint(&canvas, true); |
| 1747 | 1747 |
| 1748 scoped_refptr<OSExchangeData> data(new OSExchangeData); | 1748 scoped_refptr<OSExchangeData> data(new OSExchangeData); |
| 1749 item->GetDelegate()->WriteDragData(item, data.get()); | 1749 item->GetDelegate()->WriteDragData(item, data.get()); |
| 1750 drag_utils::SetDragImageOnDataObject(canvas, item->width(), | 1750 drag_utils::SetDragImageOnDataObject(canvas, item->width(), |
| 1751 item->height(), press_loc.x, | 1751 item->height(), press_loc.x(), |
| 1752 press_loc.y, data); | 1752 press_loc.y(), data); |
| 1753 | 1753 |
| 1754 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); | 1754 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); |
| 1755 int drag_ops = item->GetDelegate()->GetDragOperations(item); | 1755 int drag_ops = item->GetDelegate()->GetDragOperations(item); |
| 1756 DWORD effects; | 1756 DWORD effects; |
| 1757 StopScrolling(); | 1757 StopScrolling(); |
| 1758 DoDragDrop(data, drag_source, | 1758 DoDragDrop(data, drag_source, |
| 1759 DragDropTypes::DragOperationToDropEffect(drag_ops), | 1759 DragDropTypes::DragOperationToDropEffect(drag_ops), |
| 1760 &effects); | 1760 &effects); |
| 1761 if (GetActiveInstance() == this) { | 1761 if (GetActiveInstance() == this) { |
| 1762 if (showing_ ) { | 1762 if (showing_ ) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1790 MenuPart part = | 1790 MenuPart part = |
| 1791 GetMenuPartByScreenCoordinate(source, event.x(), event.y()); | 1791 GetMenuPartByScreenCoordinate(source, event.x(), event.y()); |
| 1792 any_menu_contains_mouse_ = (part.type == MenuPart::MENU_ITEM); | 1792 any_menu_contains_mouse_ = (part.type == MenuPart::MENU_ITEM); |
| 1793 if (event.IsRightMouseButton() && (part.type == MenuPart::MENU_ITEM && | 1793 if (event.IsRightMouseButton() && (part.type == MenuPart::MENU_ITEM && |
| 1794 part.menu)) { | 1794 part.menu)) { |
| 1795 // Set the selection immediately, making sure the submenu is only open | 1795 // Set the selection immediately, making sure the submenu is only open |
| 1796 // if it already was. | 1796 // if it already was. |
| 1797 bool open_submenu = (state_.item == pending_state_.item && | 1797 bool open_submenu = (state_.item == pending_state_.item && |
| 1798 state_.submenu_open); | 1798 state_.submenu_open); |
| 1799 SetSelection(pending_state_.item, open_submenu, true); | 1799 SetSelection(pending_state_.item, open_submenu, true); |
| 1800 CPoint loc(event.x(), event.y()); | 1800 gfx::Point loc(event.location()); |
| 1801 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); | 1801 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); |
| 1802 | 1802 |
| 1803 // If we open a context menu just return now | 1803 // If we open a context menu just return now |
| 1804 if (part.menu->GetDelegate()->ShowContextMenu( | 1804 if (part.menu->GetDelegate()->ShowContextMenu( |
| 1805 part.menu, part.menu->GetCommand(), loc.x, loc.y, true)) | 1805 part.menu, part.menu->GetCommand(), loc.x(), loc.y(), true)) |
| 1806 return; | 1806 return; |
| 1807 } | 1807 } |
| 1808 | 1808 |
| 1809 if (!part.is_scroll() && part.menu && !part.menu->HasSubmenu()) { | 1809 if (!part.is_scroll() && part.menu && !part.menu->HasSubmenu()) { |
| 1810 if (part.menu->GetDelegate()->IsTriggerableEvent(event)) { | 1810 if (part.menu->GetDelegate()->IsTriggerableEvent(event)) { |
| 1811 Accept(part.menu, event.GetFlags()); | 1811 Accept(part.menu, event.GetFlags()); |
| 1812 return; | 1812 return; |
| 1813 } | 1813 } |
| 1814 } else if (part.type == MenuPart::MENU_ITEM) { | 1814 } else if (part.type == MenuPart::MENU_ITEM) { |
| 1815 // User either clicked on empty space, or a menu that has children. | 1815 // User either clicked on empty space, or a menu that has children. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 | 1860 |
| 1861 void MenuController::OnDragEntered(SubmenuView* source, | 1861 void MenuController::OnDragEntered(SubmenuView* source, |
| 1862 const DropTargetEvent& event) { | 1862 const DropTargetEvent& event) { |
| 1863 valid_drop_coordinates_ = false; | 1863 valid_drop_coordinates_ = false; |
| 1864 } | 1864 } |
| 1865 | 1865 |
| 1866 int MenuController::OnDragUpdated(SubmenuView* source, | 1866 int MenuController::OnDragUpdated(SubmenuView* source, |
| 1867 const DropTargetEvent& event) { | 1867 const DropTargetEvent& event) { |
| 1868 StopCancelAllTimer(); | 1868 StopCancelAllTimer(); |
| 1869 | 1869 |
| 1870 CPoint screen_loc(event.x(), event.y()); | 1870 gfx::Point screen_loc(event.location()); |
| 1871 View::ConvertPointToScreen(source, &screen_loc); | 1871 View::ConvertPointToScreen(source, &screen_loc); |
| 1872 if (valid_drop_coordinates_ && screen_loc.x == drop_x_ && | 1872 if (valid_drop_coordinates_ && screen_loc.x() == drop_x_ && |
| 1873 screen_loc.y == drop_y_) { | 1873 screen_loc.y() == drop_y_) { |
| 1874 return last_drop_operation_; | 1874 return last_drop_operation_; |
| 1875 } | 1875 } |
| 1876 drop_x_ = screen_loc.x; | 1876 drop_x_ = screen_loc.x(); |
| 1877 drop_y_ = screen_loc.y; | 1877 drop_y_ = screen_loc.y(); |
| 1878 valid_drop_coordinates_ = true; | 1878 valid_drop_coordinates_ = true; |
| 1879 | 1879 |
| 1880 MenuItemView* menu_item = GetMenuItemAt(source, event.x(), event.y()); | 1880 MenuItemView* menu_item = GetMenuItemAt(source, event.x(), event.y()); |
| 1881 bool over_empty_menu = false; | 1881 bool over_empty_menu = false; |
| 1882 if (!menu_item) { | 1882 if (!menu_item) { |
| 1883 // See if we're over an empty menu. | 1883 // See if we're over an empty menu. |
| 1884 menu_item = GetEmptyMenuItemAt(source, event.x(), event.y()); | 1884 menu_item = GetEmptyMenuItemAt(source, event.x(), event.y()); |
| 1885 if (menu_item) | 1885 if (menu_item) |
| 1886 over_empty_menu = true; | 1886 over_empty_menu = true; |
| 1887 } | 1887 } |
| 1888 MenuDelegate::DropPosition drop_position = MenuDelegate::DROP_NONE; | 1888 MenuDelegate::DropPosition drop_position = MenuDelegate::DROP_NONE; |
| 1889 int drop_operation = DragDropTypes::DRAG_NONE; | 1889 int drop_operation = DragDropTypes::DRAG_NONE; |
| 1890 if (menu_item) { | 1890 if (menu_item) { |
| 1891 CPoint menu_item_loc(event.x(), event.y()); | 1891 gfx::Point menu_item_loc(event.location()); |
| 1892 View::ConvertPointToView(source, menu_item, &menu_item_loc); | 1892 View::ConvertPointToView(source, menu_item, &menu_item_loc); |
| 1893 MenuItemView* query_menu_item; | 1893 MenuItemView* query_menu_item; |
| 1894 if (!over_empty_menu) { | 1894 if (!over_empty_menu) { |
| 1895 int menu_item_height = menu_item->height(); | 1895 int menu_item_height = menu_item->height(); |
| 1896 if (menu_item->HasSubmenu() && | 1896 if (menu_item->HasSubmenu() && |
| 1897 (menu_item_loc.y > MenuItemView::kDropBetweenPixels && | 1897 (menu_item_loc.y() > MenuItemView::kDropBetweenPixels && |
| 1898 menu_item_loc.y < (menu_item_height - | 1898 menu_item_loc.y() < (menu_item_height - |
| 1899 MenuItemView::kDropBetweenPixels))) { | 1899 MenuItemView::kDropBetweenPixels))) { |
| 1900 drop_position = MenuDelegate::DROP_ON; | 1900 drop_position = MenuDelegate::DROP_ON; |
| 1901 } else if (menu_item_loc.y < menu_item_height / 2) { | 1901 } else if (menu_item_loc.y() < menu_item_height / 2) { |
| 1902 drop_position = MenuDelegate::DROP_BEFORE; | 1902 drop_position = MenuDelegate::DROP_BEFORE; |
| 1903 } else { | 1903 } else { |
| 1904 drop_position = MenuDelegate::DROP_AFTER; | 1904 drop_position = MenuDelegate::DROP_AFTER; |
| 1905 } | 1905 } |
| 1906 query_menu_item = menu_item; | 1906 query_menu_item = menu_item; |
| 1907 } else { | 1907 } else { |
| 1908 query_menu_item = menu_item->GetParentMenuItem(); | 1908 query_menu_item = menu_item->GetParentMenuItem(); |
| 1909 drop_position = MenuDelegate::DROP_ON; | 1909 drop_position = MenuDelegate::DROP_ON; |
| 1910 } | 1910 } |
| 1911 drop_operation = menu_item->GetDelegate()->GetDropOperation( | 1911 drop_operation = menu_item->GetDelegate()->GetDropOperation( |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 } | 2183 } |
| 2184 return false; | 2184 return false; |
| 2185 } | 2185 } |
| 2186 | 2186 |
| 2187 MenuController::MenuPart MenuController::GetMenuPartByScreenCoordinate( | 2187 MenuController::MenuPart MenuController::GetMenuPartByScreenCoordinate( |
| 2188 SubmenuView* source, | 2188 SubmenuView* source, |
| 2189 int source_x, | 2189 int source_x, |
| 2190 int source_y) { | 2190 int source_y) { |
| 2191 MenuPart part; | 2191 MenuPart part; |
| 2192 | 2192 |
| 2193 CPoint screen_loc(source_x, source_y); | 2193 gfx::Point screen_loc(source_x, source_y); |
| 2194 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | 2194 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); |
| 2195 | 2195 |
| 2196 MenuItemView* item = state_.item; | 2196 MenuItemView* item = state_.item; |
| 2197 while (item) { | 2197 while (item) { |
| 2198 if (item->HasSubmenu() && item->GetSubmenu()->IsShowing() && | 2198 if (item->HasSubmenu() && item->GetSubmenu()->IsShowing() && |
| 2199 GetMenuPartByScreenCoordinateImpl(item->GetSubmenu(), screen_loc, | 2199 GetMenuPartByScreenCoordinateImpl(item->GetSubmenu(), screen_loc, |
| 2200 &part)) { | 2200 &part)) { |
| 2201 return part; | 2201 return part; |
| 2202 } | 2202 } |
| 2203 item = item->GetParentMenuItem(); | 2203 item = item->GetParentMenuItem(); |
| 2204 } | 2204 } |
| 2205 | 2205 |
| 2206 return part; | 2206 return part; |
| 2207 } | 2207 } |
| 2208 | 2208 |
| 2209 bool MenuController::GetMenuPartByScreenCoordinateImpl( | 2209 bool MenuController::GetMenuPartByScreenCoordinateImpl( |
| 2210 SubmenuView* menu, | 2210 SubmenuView* menu, |
| 2211 const CPoint& screen_loc, | 2211 const gfx::Point& screen_loc, |
| 2212 MenuPart* part) { | 2212 MenuPart* part) { |
| 2213 // Is the mouse over the scroll buttons? | 2213 // Is the mouse over the scroll buttons? |
| 2214 CPoint scroll_view_loc = screen_loc; | 2214 gfx::Point scroll_view_loc = screen_loc; |
| 2215 View* scroll_view_container = menu->GetScrollViewContainer(); | 2215 View* scroll_view_container = menu->GetScrollViewContainer(); |
| 2216 View::ConvertPointToView(NULL, scroll_view_container, &scroll_view_loc); | 2216 View::ConvertPointToView(NULL, scroll_view_container, &scroll_view_loc); |
| 2217 if (scroll_view_loc.x < 0 || | 2217 if (scroll_view_loc.x() < 0 || |
| 2218 scroll_view_loc.x >= scroll_view_container->width() || | 2218 scroll_view_loc.x() >= scroll_view_container->width() || |
| 2219 scroll_view_loc.y < 0 || | 2219 scroll_view_loc.y() < 0 || |
| 2220 scroll_view_loc.y >= scroll_view_container->height()) { | 2220 scroll_view_loc.y() >= scroll_view_container->height()) { |
| 2221 // Point isn't contained in menu. | 2221 // Point isn't contained in menu. |
| 2222 return false; | 2222 return false; |
| 2223 } | 2223 } |
| 2224 if (IsScrollButtonAt(menu, scroll_view_loc.x, scroll_view_loc.y, | 2224 if (IsScrollButtonAt(menu, scroll_view_loc.x(), scroll_view_loc.y(), |
| 2225 &(part->type))) { | 2225 &(part->type))) { |
| 2226 part->submenu = menu; | 2226 part->submenu = menu; |
| 2227 return true; | 2227 return true; |
| 2228 } | 2228 } |
| 2229 | 2229 |
| 2230 // Not over the scroll button. Check the actual menu. | 2230 // Not over the scroll button. Check the actual menu. |
| 2231 if (DoesSubmenuContainLocation(menu, screen_loc)) { | 2231 if (DoesSubmenuContainLocation(menu, screen_loc)) { |
| 2232 CPoint menu_loc = screen_loc; | 2232 gfx::Point menu_loc = screen_loc; |
| 2233 View::ConvertPointToView(NULL, menu, &menu_loc); | 2233 View::ConvertPointToView(NULL, menu, &menu_loc); |
| 2234 part->menu = GetMenuItemAt(menu, menu_loc.x, menu_loc.y); | 2234 part->menu = GetMenuItemAt(menu, menu_loc.x(), menu_loc.y()); |
| 2235 part->type = MenuPart::MENU_ITEM; | 2235 part->type = MenuPart::MENU_ITEM; |
| 2236 return true; | 2236 return true; |
| 2237 } | 2237 } |
| 2238 | 2238 |
| 2239 // While the mouse isn't over a menu item or the scroll buttons of menu, it | 2239 // While the mouse isn't over a menu item or the scroll buttons of menu, it |
| 2240 // is contained by menu and so we return true. If we didn't return true other | 2240 // is contained by menu and so we return true. If we didn't return true other |
| 2241 // menus would be searched, even though they are likely obscured by us. | 2241 // menus would be searched, even though they are likely obscured by us. |
| 2242 return true; | 2242 return true; |
| 2243 } | 2243 } |
| 2244 | 2244 |
| 2245 bool MenuController::DoesSubmenuContainLocation(SubmenuView* submenu, | 2245 bool MenuController::DoesSubmenuContainLocation(SubmenuView* submenu, |
| 2246 const CPoint& screen_loc) { | 2246 const gfx::Point& screen_loc) { |
| 2247 CPoint view_loc = screen_loc; | 2247 gfx::Point view_loc = screen_loc; |
| 2248 View::ConvertPointToView(NULL, submenu, &view_loc); | 2248 View::ConvertPointToView(NULL, submenu, &view_loc); |
| 2249 gfx::Rect vis_rect = submenu->GetVisibleBounds(); | 2249 gfx::Rect vis_rect = submenu->GetVisibleBounds(); |
| 2250 return vis_rect.Contains(view_loc.x, view_loc.y); | 2250 return vis_rect.Contains(view_loc.x(), view_loc.y()); |
| 2251 } | 2251 } |
| 2252 | 2252 |
| 2253 void MenuController::CommitPendingSelection() { | 2253 void MenuController::CommitPendingSelection() { |
| 2254 StopShowTimer(); | 2254 StopShowTimer(); |
| 2255 | 2255 |
| 2256 size_t paths_differ_at = 0; | 2256 size_t paths_differ_at = 0; |
| 2257 std::vector<MenuItemView*> current_path; | 2257 std::vector<MenuItemView*> current_path; |
| 2258 std::vector<MenuItemView*> new_path; | 2258 std::vector<MenuItemView*> new_path; |
| 2259 BuildPathsAndCalculateDiff(state_.item, pending_state_.item, ¤t_path, | 2259 BuildPathsAndCalculateDiff(state_.item, pending_state_.item, ¤t_path, |
| 2260 &new_path, &paths_differ_at); | 2260 &new_path, &paths_differ_at); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2448 static_cast<LONG>(state_.monitor_bounds.bottom() - y)); | 2448 static_cast<LONG>(state_.monitor_bounds.bottom() - y)); |
| 2449 } else { | 2449 } else { |
| 2450 pref.cy = std::min(pref.cy, static_cast<LONG>( | 2450 pref.cy = std::min(pref.cy, static_cast<LONG>( |
| 2451 state_.initial_bounds.y() - state_.monitor_bounds.y())); | 2451 state_.initial_bounds.y() - state_.monitor_bounds.y())); |
| 2452 y = state_.initial_bounds.y() - pref.cy; | 2452 y = state_.initial_bounds.y() - pref.cy; |
| 2453 } | 2453 } |
| 2454 } | 2454 } |
| 2455 } else { | 2455 } else { |
| 2456 // Not the first menu; position it relative to the bounds of the menu | 2456 // Not the first menu; position it relative to the bounds of the menu |
| 2457 // item. | 2457 // item. |
| 2458 CPoint item_loc(0, 0); | 2458 gfx::Point item_loc; |
| 2459 View::ConvertPointToScreen(item, &item_loc); | 2459 View::ConvertPointToScreen(item, &item_loc); |
| 2460 | 2460 |
| 2461 // We must make sure we take into account the UI layout. If the layout is | 2461 // We must make sure we take into account the UI layout. If the layout is |
| 2462 // RTL, then a 'leading' menu is positioned to the left of the parent menu | 2462 // RTL, then a 'leading' menu is positioned to the left of the parent menu |
| 2463 // item and not to the right. | 2463 // item and not to the right. |
| 2464 bool layout_is_rtl = item->UILayoutIsRightToLeft(); | 2464 bool layout_is_rtl = item->UILayoutIsRightToLeft(); |
| 2465 bool create_on_the_right = (prefer_leading && !layout_is_rtl) || | 2465 bool create_on_the_right = (prefer_leading && !layout_is_rtl) || |
| 2466 (!prefer_leading && layout_is_rtl); | 2466 (!prefer_leading && layout_is_rtl); |
| 2467 | 2467 |
| 2468 if (create_on_the_right) { | 2468 if (create_on_the_right) { |
| 2469 x = item_loc.x + item->width() - kSubmenuHorizontalInset; | 2469 x = item_loc.x() + item->width() - kSubmenuHorizontalInset; |
| 2470 if (state_.monitor_bounds.width() != 0 && | 2470 if (state_.monitor_bounds.width() != 0 && |
| 2471 x + pref.cx > state_.monitor_bounds.right()) { | 2471 x + pref.cx > state_.monitor_bounds.right()) { |
| 2472 if (layout_is_rtl) | 2472 if (layout_is_rtl) |
| 2473 *is_leading = true; | 2473 *is_leading = true; |
| 2474 else | 2474 else |
| 2475 *is_leading = false; | 2475 *is_leading = false; |
| 2476 x = item_loc.x - pref.cx + kSubmenuHorizontalInset; | 2476 x = item_loc.x() - pref.cx + kSubmenuHorizontalInset; |
| 2477 } | 2477 } |
| 2478 } else { | 2478 } else { |
| 2479 x = item_loc.x - pref.cx + kSubmenuHorizontalInset; | 2479 x = item_loc.x() - pref.cx + kSubmenuHorizontalInset; |
| 2480 if (state_.monitor_bounds.width() != 0 && x < state_.monitor_bounds.x()) { | 2480 if (state_.monitor_bounds.width() != 0 && x < state_.monitor_bounds.x()) { |
| 2481 if (layout_is_rtl) | 2481 if (layout_is_rtl) |
| 2482 *is_leading = false; | 2482 *is_leading = false; |
| 2483 else | 2483 else |
| 2484 *is_leading = true; | 2484 *is_leading = true; |
| 2485 x = item_loc.x + item->width() - kSubmenuHorizontalInset; | 2485 x = item_loc.x() + item->width() - kSubmenuHorizontalInset; |
| 2486 } | 2486 } |
| 2487 } | 2487 } |
| 2488 y = item_loc.y - kSubmenuBorderSize; | 2488 y = item_loc.y() - kSubmenuBorderSize; |
| 2489 if (state_.monitor_bounds.width() != 0) { | 2489 if (state_.monitor_bounds.width() != 0) { |
| 2490 pref.cy = std::min(pref.cy, | 2490 pref.cy = std::min(pref.cy, |
| 2491 static_cast<LONG>(state_.monitor_bounds.height())); | 2491 static_cast<LONG>(state_.monitor_bounds.height())); |
| 2492 if (y + pref.cy > state_.monitor_bounds.bottom()) | 2492 if (y + pref.cy > state_.monitor_bounds.bottom()) |
| 2493 y = state_.monitor_bounds.bottom() - pref.cy; | 2493 y = state_.monitor_bounds.bottom() - pref.cy; |
| 2494 if (y < state_.monitor_bounds.y()) | 2494 if (y < state_.monitor_bounds.y()) |
| 2495 y = state_.monitor_bounds.y(); | 2495 y = state_.monitor_bounds.y(); |
| 2496 } | 2496 } |
| 2497 } | 2497 } |
| 2498 | 2498 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2629 SetSelection(submenu->GetMenuItemAt(first_match), false, false); | 2629 SetSelection(submenu->GetMenuItemAt(first_match), false, false); |
| 2630 } else { | 2630 } else { |
| 2631 SetSelection(submenu->GetMenuItemAt(next_match), false, false); | 2631 SetSelection(submenu->GetMenuItemAt(next_match), false, false); |
| 2632 } | 2632 } |
| 2633 } | 2633 } |
| 2634 return false; | 2634 return false; |
| 2635 } | 2635 } |
| 2636 | 2636 |
| 2637 void MenuController::RepostEvent(SubmenuView* source, | 2637 void MenuController::RepostEvent(SubmenuView* source, |
| 2638 const MouseEvent& event) { | 2638 const MouseEvent& event) { |
| 2639 CPoint screen_loc(event.x(), event.y()); | 2639 gfx::Point screen_loc(event.location()); |
| 2640 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | 2640 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); |
| 2641 HWND window = WindowFromPoint(screen_loc); | 2641 HWND window = WindowFromPoint(screen_loc.ToPOINT()); |
| 2642 if (window) { | 2642 if (window) { |
| 2643 #ifdef DEBUG_MENU | 2643 #ifdef DEBUG_MENU |
| 2644 DLOG(INFO) << "RepostEvent on press"; | 2644 DLOG(INFO) << "RepostEvent on press"; |
| 2645 #endif | 2645 #endif |
| 2646 | 2646 |
| 2647 // Release the capture. | 2647 // Release the capture. |
| 2648 SubmenuView* submenu = state_.item->GetRootMenuItem()->GetSubmenu(); | 2648 SubmenuView* submenu = state_.item->GetRootMenuItem()->GetSubmenu(); |
| 2649 submenu->ReleaseCapture(); | 2649 submenu->ReleaseCapture(); |
| 2650 | 2650 |
| 2651 if (submenu->host() && submenu->host()->GetHWND() && | 2651 if (submenu->host() && submenu->host()->GetHWND() && |
| 2652 GetWindowThreadProcessId(submenu->host()->GetHWND(), NULL) != | 2652 GetWindowThreadProcessId(submenu->host()->GetHWND(), NULL) != |
| 2653 GetWindowThreadProcessId(window, NULL)) { | 2653 GetWindowThreadProcessId(window, NULL)) { |
| 2654 // Even though we have mouse capture, windows generates a mouse event | 2654 // Even though we have mouse capture, windows generates a mouse event |
| 2655 // if the other window is in a separate thread. Don't generate an event in | 2655 // if the other window is in a separate thread. Don't generate an event in |
| 2656 // this case else the target window can get double events leading to bad | 2656 // this case else the target window can get double events leading to bad |
| 2657 // behavior. | 2657 // behavior. |
| 2658 return; | 2658 return; |
| 2659 } | 2659 } |
| 2660 | 2660 |
| 2661 // Convert the coordinates to the target window. | 2661 // Convert the coordinates to the target window. |
| 2662 RECT window_bounds; | 2662 RECT window_bounds; |
| 2663 GetWindowRect(window, &window_bounds); | 2663 GetWindowRect(window, &window_bounds); |
| 2664 int window_x = screen_loc.x - window_bounds.left; | 2664 int window_x = screen_loc.x() - window_bounds.left; |
| 2665 int window_y = screen_loc.y - window_bounds.top; | 2665 int window_y = screen_loc.y() - window_bounds.top; |
| 2666 | 2666 |
| 2667 // Determine whether the click was in the client area or not. | 2667 // Determine whether the click was in the client area or not. |
| 2668 // NOTE: WM_NCHITTEST coordinates are relative to the screen. | 2668 // NOTE: WM_NCHITTEST coordinates are relative to the screen. |
| 2669 LRESULT nc_hit_result = SendMessage(window, WM_NCHITTEST, 0, | 2669 LRESULT nc_hit_result = SendMessage(window, WM_NCHITTEST, 0, |
| 2670 MAKELPARAM(screen_loc.x, screen_loc.y)); | 2670 MAKELPARAM(screen_loc.x(), |
| 2671 screen_loc.y())); |
| 2671 const bool in_client_area = (nc_hit_result == HTCLIENT); | 2672 const bool in_client_area = (nc_hit_result == HTCLIENT); |
| 2672 | 2673 |
| 2673 // TODO(sky): this isn't right. The event to generate should correspond | 2674 // TODO(sky): this isn't right. The event to generate should correspond |
| 2674 // with the event we just got. MouseEvent only tells us what is down, | 2675 // with the event we just got. MouseEvent only tells us what is down, |
| 2675 // which may differ. Need to add ability to get changed button from | 2676 // which may differ. Need to add ability to get changed button from |
| 2676 // MouseEvent. | 2677 // MouseEvent. |
| 2677 int event_type; | 2678 int event_type; |
| 2678 if (event.IsLeftMouseButton()) | 2679 if (event.IsLeftMouseButton()) |
| 2679 event_type = in_client_area ? WM_LBUTTONDOWN : WM_NCLBUTTONDOWN; | 2680 event_type = in_client_area ? WM_LBUTTONDOWN : WM_NCLBUTTONDOWN; |
| 2680 else if (event.IsMiddleMouseButton()) | 2681 else if (event.IsMiddleMouseButton()) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 scroll_task_.reset(new MenuScrollTask()); | 2723 scroll_task_.reset(new MenuScrollTask()); |
| 2723 scroll_task_->Update(part); | 2724 scroll_task_->Update(part); |
| 2724 } | 2725 } |
| 2725 | 2726 |
| 2726 void MenuController::StopScrolling() { | 2727 void MenuController::StopScrolling() { |
| 2727 scroll_task_.reset(NULL); | 2728 scroll_task_.reset(NULL); |
| 2728 } | 2729 } |
| 2729 | 2730 |
| 2730 } // namespace ChromeViews | 2731 } // namespace ChromeViews |
| 2731 | 2732 |
| OLD | NEW |