window_open_disposition.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/base/window_open_disposition.h"
  5. #include "build/build_config.h"
  6. #include "ui/events/event_constants.h"
  7. namespace ui {
  8. WindowOpenDisposition DispositionFromClick(
  9. bool middle_button,
  10. bool alt_key,
  11. bool ctrl_key,
  12. bool meta_key,
  13. bool shift_key,
  14. WindowOpenDisposition disposition_for_current_tab) {
  15. // MacOS uses meta key (Command key) to spawn new tabs.
  16. #if BUILDFLAG(IS_APPLE)
  17. if (middle_button || meta_key)
  18. #else
  19. if (middle_button || ctrl_key)
  20. #endif
  21. return shift_key ? WindowOpenDisposition::NEW_FOREGROUND_TAB
  22. : WindowOpenDisposition::NEW_BACKGROUND_TAB;
  23. if (shift_key)
  24. return WindowOpenDisposition::NEW_WINDOW;
  25. if (alt_key)
  26. return WindowOpenDisposition::SAVE_TO_DISK;
  27. return disposition_for_current_tab;
  28. }
  29. WindowOpenDisposition DispositionFromEventFlags(
  30. int event_flags,
  31. WindowOpenDisposition disposition_for_current_tab) {
  32. return DispositionFromClick((event_flags & ui::EF_MIDDLE_MOUSE_BUTTON) != 0,
  33. (event_flags & ui::EF_ALT_DOWN) != 0,
  34. (event_flags & ui::EF_CONTROL_DOWN) != 0,
  35. (event_flags & ui::EF_COMMAND_DOWN) != 0,
  36. (event_flags & ui::EF_SHIFT_DOWN) != 0,
  37. disposition_for_current_tab);
  38. }
  39. } // namespace ui