| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/ui/views/frame/opaque_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "ui/gfx/canvas_skia.h" | 35 #include "ui/gfx/canvas_skia.h" |
| 36 #include "ui/gfx/font.h" | 36 #include "ui/gfx/font.h" |
| 37 #include "ui/gfx/image/image.h" | 37 #include "ui/gfx/image/image.h" |
| 38 #include "ui/gfx/path.h" | 38 #include "ui/gfx/path.h" |
| 39 #include "ui/views/controls/button/image_button.h" | 39 #include "ui/views/controls/button/image_button.h" |
| 40 #include "ui/views/controls/image_view.h" | 40 #include "ui/views/controls/image_view.h" |
| 41 #include "ui/views/widget/root_view.h" | 41 #include "ui/views/widget/root_view.h" |
| 42 #include "ui/views/window/frame_background.h" | 42 #include "ui/views/window/frame_background.h" |
| 43 #include "ui/views/window/window_shape.h" | 43 #include "ui/views/window/window_shape.h" |
| 44 | 44 |
| 45 #if defined(USE_AURA) |
| 46 #include "ui/aura/aura_switches.h" |
| 47 #endif |
| 48 |
| 45 #if defined(USE_VIRTUAL_KEYBOARD) | 49 #if defined(USE_VIRTUAL_KEYBOARD) |
| 46 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" | 50 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" |
| 47 #endif | 51 #endif |
| 48 | 52 |
| 49 namespace { | 53 namespace { |
| 50 // The frame border is only visible in restored mode and is hardcoded to 4 px on | 54 // The frame border is only visible in restored mode and is hardcoded to 4 px on |
| 51 // each side regardless of the system window border size. | 55 // each side regardless of the system window border size. |
| 52 const int kFrameBorderThickness = 4; | 56 const int kFrameBorderThickness = 4; |
| 53 // Besides the frame border, there's another 11 px of empty space atop the | 57 // Besides the frame border, there's another 11 px of empty space atop the |
| 54 // window in restored mode, to use to drag the window around. | 58 // window in restored mode, to use to drag the window around. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ALLOW_THIS_IN_INITIALIZER_LIST( | 129 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 126 restore_button_(new views::ImageButton(this))), | 130 restore_button_(new views::ImageButton(this))), |
| 127 ALLOW_THIS_IN_INITIALIZER_LIST( | 131 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 128 close_button_(new views::ImageButton(this))), | 132 close_button_(new views::ImageButton(this))), |
| 129 window_icon_(NULL), | 133 window_icon_(NULL), |
| 130 frame_background_(new views::FrameBackground()) { | 134 frame_background_(new views::FrameBackground()) { |
| 131 ui::ThemeProvider* tp = frame->GetThemeProvider(); | 135 ui::ThemeProvider* tp = frame->GetThemeProvider(); |
| 132 SkColor color = tp->GetColor(ThemeService::COLOR_BUTTON_BACKGROUND); | 136 SkColor color = tp->GetColor(ThemeService::COLOR_BUTTON_BACKGROUND); |
| 133 SkBitmap* background = | 137 SkBitmap* background = |
| 134 tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND); | 138 tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND); |
| 139 // TODO(jamescook): Refactor button setup into one button setup function. |
| 135 minimize_button_->SetImage(views::CustomButton::BS_NORMAL, | 140 minimize_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 136 tp->GetBitmapNamed(IDR_MINIMIZE)); | 141 tp->GetBitmapNamed(IDR_MINIMIZE)); |
| 137 minimize_button_->SetImage(views::CustomButton::BS_HOT, | 142 minimize_button_->SetImage(views::CustomButton::BS_HOT, |
| 138 tp->GetBitmapNamed(IDR_MINIMIZE_H)); | 143 tp->GetBitmapNamed(IDR_MINIMIZE_H)); |
| 139 minimize_button_->SetImage(views::CustomButton::BS_PUSHED, | 144 minimize_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 140 tp->GetBitmapNamed(IDR_MINIMIZE_P)); | 145 tp->GetBitmapNamed(IDR_MINIMIZE_P)); |
| 141 if (browser_view->IsBrowserTypeNormal()) { | 146 if (browser_view->IsBrowserTypeNormal()) { |
| 142 minimize_button_->SetBackground(color, background, | 147 minimize_button_->SetBackground(color, background, |
| 143 tp->GetBitmapNamed(IDR_MINIMIZE_BUTTON_MASK)); | 148 tp->GetBitmapNamed(IDR_MINIMIZE_BUTTON_MASK)); |
| 144 } | 149 } |
| 145 minimize_button_->SetAccessibleName( | 150 minimize_button_->SetAccessibleName( |
| 146 l10n_util::GetStringUTF16(IDS_ACCNAME_MINIMIZE)); | 151 l10n_util::GetStringUTF16(IDS_ACCNAME_MINIMIZE)); |
| 147 AddChildView(minimize_button_); | 152 AddChildView(minimize_button_); |
| 148 #if defined(USE_AURA) | |
| 149 // TODO(jamescook): Remove this when Aura uses its own custom window frame, | |
| 150 // BrowserNonClientFrameViewAura. Layout code depends on this button's | |
| 151 // position, so just hide it. | |
| 152 minimize_button_->SetVisible(false); | |
| 153 #endif | |
| 154 | 153 |
| 155 maximize_button_->SetImage(views::CustomButton::BS_NORMAL, | 154 maximize_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 156 tp->GetBitmapNamed(IDR_MAXIMIZE)); | 155 tp->GetBitmapNamed(IDR_MAXIMIZE)); |
| 157 maximize_button_->SetImage(views::CustomButton::BS_HOT, | 156 maximize_button_->SetImage(views::CustomButton::BS_HOT, |
| 158 tp->GetBitmapNamed(IDR_MAXIMIZE_H)); | 157 tp->GetBitmapNamed(IDR_MAXIMIZE_H)); |
| 159 maximize_button_->SetImage(views::CustomButton::BS_PUSHED, | 158 maximize_button_->SetImage(views::CustomButton::BS_PUSHED, |
| 160 tp->GetBitmapNamed(IDR_MAXIMIZE_P)); | 159 tp->GetBitmapNamed(IDR_MAXIMIZE_P)); |
| 161 if (browser_view->IsBrowserTypeNormal()) { | 160 if (browser_view->IsBrowserTypeNormal()) { |
| 162 maximize_button_->SetBackground(color, background, | 161 maximize_button_->SetBackground(color, background, |
| 163 tp->GetBitmapNamed(IDR_MAXIMIZE_BUTTON_MASK)); | 162 tp->GetBitmapNamed(IDR_MAXIMIZE_BUTTON_MASK)); |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 // side of the caption buttons. In maximized mode we extend the rightmost | 937 // side of the caption buttons. In maximized mode we extend the rightmost |
| 939 // button to the screen corner to obey Fitts' Law. | 938 // button to the screen corner to obey Fitts' Law. |
| 940 int right_extra_width = is_maximized ? | 939 int right_extra_width = is_maximized ? |
| 941 (kFrameBorderThickness - kFrameShadowThickness) : 0; | 940 (kFrameBorderThickness - kFrameShadowThickness) : 0; |
| 942 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 941 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
| 943 close_button_->SetBounds(width() - FrameBorderThickness(false) - | 942 close_button_->SetBounds(width() - FrameBorderThickness(false) - |
| 944 right_extra_width - close_button_size.width(), caption_y, | 943 right_extra_width - close_button_size.width(), caption_y, |
| 945 close_button_size.width() + right_extra_width, | 944 close_button_size.width() + right_extra_width, |
| 946 close_button_size.height()); | 945 close_button_size.height()); |
| 947 | 946 |
| 948 #if defined(OS_CHROMEOS) && !defined(USE_AURA) | 947 // Both ChromeOS and Aura laptop mode use a single main window. |
| 949 // LayoutWindowControls could be triggered from | 948 if (frame()->IsSingleWindowMode()) { |
| 950 // NativeWidgetGtk::UpdateWindowTitle(), which could happen when user | 949 // LayoutWindowControls could be triggered from |
| 951 // navigates in fullscreen mode. And because | 950 // NativeWidgetGtk::UpdateWindowTitle(), which could happen when user |
| 952 // BrowserFrameChromeos::IsMaximized() return false for fullscreen mode, we | 951 // navigates in fullscreen mode. And because |
| 953 // explicitly test fullscreen mode here and make it use the same code path | 952 // BrowserFrameChromeos::IsMaximized() return false for fullscreen mode, we |
| 954 // as maximized mode. | 953 // explicitly test fullscreen mode here and make it use the same code path |
| 955 // TODO(oshima): Optimize the relayout logic to defer the frame view's | 954 // as maximized mode. |
| 956 // relayout until it is necessary, i.e when it becomes visible. | 955 // TODO(oshima): Optimize the relayout logic to defer the frame view's |
| 957 if (is_maximized || frame()->IsFullscreen()) { | 956 // relayout until it is necessary, i.e when it becomes visible. |
| 958 minimize_button_->SetVisible(false); | 957 if (is_maximized || frame()->IsFullscreen()) { |
| 959 restore_button_->SetVisible(false); | 958 minimize_button_->SetVisible(false); |
| 960 maximize_button_->SetVisible(false); | 959 restore_button_->SetVisible(false); |
| 960 maximize_button_->SetVisible(false); |
| 961 | 961 |
| 962 if (browser_view()->browser()->is_devtools()) { | 962 if (browser_view()->browser()->is_devtools()) { |
| 963 close_button_->SetVisible(true); | 963 close_button_->SetVisible(true); |
| 964 minimize_button_->SetBounds(close_button_->bounds().x(), 0, 0, 0); | 964 minimize_button_->SetBounds(close_button_->bounds().x(), 0, 0, 0); |
| 965 } else { | 965 } else { |
| 966 close_button_->SetVisible(false); | 966 close_button_->SetVisible(false); |
| 967 // Set the bounds of the minimize button so that we don't have to change | 967 // Set the bounds of the minimize button so that we don't have to change |
| 968 // other places that rely on the bounds. Put it slightly to the right | 968 // other places that rely on the bounds. Put it slightly to the right |
| 969 // of the edge of the view, so that when we remove the spacing it lines | 969 // of the edge of the view, so that when we remove the spacing it lines |
| 970 // up with the edge. | 970 // up with the edge. |
| 971 minimize_button_->SetBounds(width() - FrameBorderThickness(false) + | 971 minimize_button_->SetBounds(width() - FrameBorderThickness(false) + |
| 972 kNewTabCaptionMaximizedSpacing, 0, 0, 0); | 972 kNewTabCaptionMaximizedSpacing, 0, 0, 0); |
| 973 } |
| 974 return; |
| 973 } | 975 } |
| 974 | |
| 975 return; | |
| 976 } else { | |
| 977 close_button_->SetVisible(true); | 976 close_button_->SetVisible(true); |
| 978 } | 977 } |
| 979 #endif | |
| 980 | 978 |
| 981 // When the window is restored, we show a maximized button; otherwise, we show | 979 // When the window is restored, we show a maximized button; otherwise, we show |
| 982 // a restore button. | 980 // a restore button. |
| 983 bool is_restored = !is_maximized && !frame()->IsMinimized(); | 981 bool is_restored = !is_maximized && !frame()->IsMinimized(); |
| 984 views::ImageButton* invisible_button = is_restored ? | 982 views::ImageButton* invisible_button = is_restored ? |
| 985 restore_button_ : maximize_button_; | 983 restore_button_ : maximize_button_; |
| 986 invisible_button->SetVisible(false); | 984 invisible_button->SetVisible(false); |
| 987 | 985 |
| 988 views::ImageButton* visible_button = is_restored ? | 986 views::ImageButton* visible_button = is_restored ? |
| 989 maximize_button_ : restore_button_; | 987 maximize_button_ : restore_button_; |
| 990 visible_button->SetVisible(true); | 988 visible_button->SetVisible(true); |
| 991 visible_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | 989 visible_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT, |
| 992 views::ImageButton::ALIGN_BOTTOM); | 990 views::ImageButton::ALIGN_BOTTOM); |
| 993 gfx::Size visible_button_size = visible_button->GetPreferredSize(); | 991 gfx::Size visible_button_size = visible_button->GetPreferredSize(); |
| 994 visible_button->SetBounds(close_button_->x() - visible_button_size.width(), | 992 visible_button->SetBounds(close_button_->x() - visible_button_size.width(), |
| 995 caption_y, visible_button_size.width(), | 993 caption_y, visible_button_size.width(), |
| 996 visible_button_size.height()); | 994 visible_button_size.height()); |
| 997 | 995 |
| 998 #if !defined(USE_AURA) | 996 #if defined(USE_AURA) |
| 999 // TODO(jamescook): Go back to showing minimize button when Aura uses its | 997 // TODO(jamescook): Go back to showing minimize button when Aura uses its |
| 1000 // own custom window frame, BrowserNonClientFrameViewAura. | 998 // own custom window frame, BrowserNonClientFrameViewAura. |
| 999 minimize_button_->SetVisible(false); |
| 1000 #else |
| 1001 minimize_button_->SetVisible(true); | 1001 minimize_button_->SetVisible(true); |
| 1002 #endif | 1002 #endif |
| 1003 minimize_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | 1003 minimize_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, |
| 1004 views::ImageButton::ALIGN_BOTTOM); | 1004 views::ImageButton::ALIGN_BOTTOM); |
| 1005 gfx::Size minimize_button_size = minimize_button_->GetPreferredSize(); | 1005 gfx::Size minimize_button_size = minimize_button_->GetPreferredSize(); |
| 1006 minimize_button_->SetBounds( | 1006 minimize_button_->SetBounds( |
| 1007 visible_button->x() - minimize_button_size.width(), caption_y, | 1007 visible_button->x() - minimize_button_size.width(), caption_y, |
| 1008 minimize_button_size.width(), | 1008 minimize_button_size.width(), |
| 1009 minimize_button_size.height()); | 1009 minimize_button_size.height()); |
| 1010 } | 1010 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 | 1056 |
| 1057 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, | 1057 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, |
| 1058 int height) const { | 1058 int height) const { |
| 1059 int top_height = NonClientTopBorderHeight(false); | 1059 int top_height = NonClientTopBorderHeight(false); |
| 1060 int border_thickness = NonClientBorderThickness(); | 1060 int border_thickness = NonClientBorderThickness(); |
| 1061 return gfx::Rect(border_thickness, top_height, | 1061 return gfx::Rect(border_thickness, top_height, |
| 1062 std::max(0, width - (2 * border_thickness)), | 1062 std::max(0, width - (2 * border_thickness)), |
| 1063 std::max(0, height - GetReservedHeight() - | 1063 std::max(0, height - GetReservedHeight() - |
| 1064 top_height - border_thickness)); | 1064 top_height - border_thickness)); |
| 1065 } | 1065 } |
| OLD | NEW |