File: desktop_browser_frame_aura_linux.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,770 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/frame/desktop_browser_frame_aura_linux.h"

#include "base/command_line.h"
#include "base/functional/bind.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration_linux.h"
#include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_linux.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/native_browser_frame_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/views/widget/widget.h"

DesktopBrowserFrameAuraLinux::DesktopBrowserFrameAuraLinux(
    BrowserFrame* browser_frame,
    BrowserView* browser_view)
    : DesktopBrowserFrameAura(browser_frame, browser_view) {
  use_custom_frame_pref_.Init(
      prefs::kUseCustomChromeFrame,
      browser_view->browser()->profile()->GetPrefs(),
      base::BindRepeating(
          &DesktopBrowserFrameAuraLinux::OnUseCustomChromeFrameChanged,
          base::Unretained(this)));
}

DesktopBrowserFrameAuraLinux::~DesktopBrowserFrameAuraLinux() = default;

views::Widget::InitParams DesktopBrowserFrameAuraLinux::GetWidgetParams(
    views::Widget::InitParams::Ownership ownership) {
  views::Widget::InitParams params(ownership);
  params.native_widget = this;

  // Set up a custom WM_CLASS for some sorts of window types. This allows
  // task switchers in X11 environments to distinguish between main browser
  // windows and e.g app windows.
  const Browser& browser = *browser_view()->browser();
  params.wm_class_name =
      (browser.is_type_app() || browser.is_type_app_popup())
          ? shell_integration_linux::GetWMClassFromAppName(browser.app_name())
          // This window is a hosted app or v1 packaged app.
          // NOTE: v2 packaged app windows are created by
          // ChromeNativeAppWindowViews.
          : shell_integration_linux::GetProgramClassName();
  params.wm_class_class = shell_integration_linux::GetProgramClassClass();
  const char kX11WindowRoleBrowser[] = "browser";
  const char kX11WindowRolePopup[] = "pop-up";
  params.wm_role_name = browser_view()->browser()->is_type_normal()
                            ? std::string(kX11WindowRoleBrowser)
                            : std::string(kX11WindowRolePopup);
  params.remove_standard_frame = UseCustomFrame();
  params.opacity = views::Widget::InitParams::WindowOpacity::kTranslucent;

  if ((browser.is_type_app() || browser.is_type_app_popup()) &&
      browser.profile()) {
    params.wayland_app_id = shell_integration_linux::GetXdgAppIdForWebApp(
        browser.app_name(), browser.profile()->GetPath());
  } else {
    params.wayland_app_id = params.wm_class_class;
  }

  return params;
}

bool DesktopBrowserFrameAuraLinux::UseCustomFrame() const {
  // If the platform does not support server side decorations, ignore the user
  // preference and return true.
  if (!ui::OzonePlatform::GetInstance()
           ->GetPlatformRuntimeProperties()
           .supports_server_side_window_decorations) {
    return true;
  }

  // Normal browser windows get a custom frame (per the user's preference).
  if (use_custom_frame_pref_.GetValue() && browser_view()->GetIsNormalType()) {
    return true;
  }

  // Hosted app windows get a custom frame (if the desktop PWA experimental
  // feature is enabled), or if the window is picture in picture.
  return browser_view()->GetIsWebAppType() ||
         browser_view()->GetIsPictureInPictureType();
}

void DesktopBrowserFrameAuraLinux::TabDraggingKindChanged(
    TabDragKind tab_drag_kind) {
  host_->TabDraggingKindChanged(tab_drag_kind);
}

void DesktopBrowserFrameAuraLinux::ClientDestroyedWidget() {
  use_custom_frame_pref_.Destroy();
  DesktopBrowserFrameAura::ClientDestroyedWidget();
}

bool DesktopBrowserFrameAuraLinux::ShouldDrawRestoredFrameShadow() const {
  return host_->SupportsClientFrameShadow() && UseCustomFrame();
}

void DesktopBrowserFrameAuraLinux::OnUseCustomChromeFrameChanged() {
  // Tell the window manager to add or remove system borders.
  browser_frame()->set_frame_type(UseCustomFrame()
                                      ? views::Widget::FrameType::kForceCustom
                                      : views::Widget::FrameType::kForceNative);
  browser_frame()->FrameTypeChanged();
  host_->UpdateFrameHints();
}

NativeBrowserFrame* NativeBrowserFrameFactory::Create(
    BrowserFrame* browser_frame,
    BrowserView* browser_view) {
  return new DesktopBrowserFrameAuraLinux(browser_frame, browser_view);
}